梦影幻å¿
2016-11-05 00:38:28 UTC
Code:
#include "sdl\SDL.h"
SDL_Texture* Image1;
SDL_Rect I1;
SDL_Surface* Image2;
SDL_Rect I2;
int testshow = 1;
int wmain()
{
SDL_Window* pWindow = NULL;
SDL_Renderer* pRenderer = NULL;
SDL_Surface* screen = NULL;
SDL_Init(SDL_INIT_EVERYTHING);
pWindow = SDL_CreateWindow(u8"æµè¯çªå£", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1920, 1080, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
pRenderer = SDL_CreateRenderer(pWindow, -1, 0);
screen = SDL_GetWindowSurface(pWindow);
//read 1.bmp 300x300 bgr
char ImageBuffer[300 * 300 * 3];
FILE* infile;
_wfopen_s(&infile, L"1.bmp", L"rb");
fseek(infile, 54, SEEK_SET);
fread(ImageBuffer, sizeof(ImageBuffer), 1, infile);
fclose(infile);
SDL_Surface* buffer = SDL_CreateRGBSurfaceFrom(ImageBuffer, 300, 300, 3 * 8, 300 * 3, 0x0000FF, 0x00FF00, 0xFF0000, 0x000000);
Image1 = SDL_CreateTextureFromSurface(pRenderer, buffer);
I1.x = I1.y = 20;I1.w = I1.h = 300;
//read 2.bmp 300x300 bgr
_wfopen_s(&infile, L"2.bmp", L"rb");
fseek(infile, 54, SEEK_SET);
fread(ImageBuffer, sizeof(ImageBuffer), 1, infile);
fclose(infile);
Image2 = SDL_CreateRGBSurfaceFrom(ImageBuffer, 300, 300, 3 * 8, 300 * 3, 0x0000FF, 0x00FF00, 0xFF0000, 0x000000);
I2.x = 350;I2.y = 20;I2.w = I2.h = 300;
SDL_Event event;
bool sQuit = false;
while (!sQuit)
{
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE)
{
sQuit = true;
}
if (event.key.keysym.sym == SDLK_1)
{
testshow = 1;
}
if (event.key.keysym.sym == SDLK_2)
{
testshow = 2;
}
break;
case SDL_QUIT:
sQuit = true;
break;
default:
break;
}
}
//SDL_RenderClear(pRenderer);
SDL_RenderCopy(pRenderer, Image1, NULL, &I1);//video card memory data
SDL_BlitSurface(Image2, NULL, screen, &I2);//random access memory data
//I want two methods for image render, but output image will flickering. could have only one.
SDL_RenderPresent(pRenderer);//video card render mode
SDL_UpdateWindowSurface(pWindow);//random access memory render mode
/*
switch (testshow)
{
case 1:
SDL_RenderClear(pRenderer);
SDL_RenderCopy(pRenderer, Image1, NULL, &I1);
SDL_RenderPresent(pRenderer);
break;
case 2:
SDL_BlitSurface(Image2, NULL, screen, &I2);
SDL_UpdateWindowSurface(pWindow);
break;
}
*/
}
SDL_Quit();
}
I want "SDL_RenderPresent" and "SDL_UpdateWindowSurface" in the same screen.
For example, âSDL_Textureâ is normal image, âSDL_Surfaceâ is Chinese characters. about render font, render âSDL_Surfaceâ,Instead of from âSDL_Surfaceâ to âSDL_Textureâ.
#include "sdl\SDL.h"
SDL_Texture* Image1;
SDL_Rect I1;
SDL_Surface* Image2;
SDL_Rect I2;
int testshow = 1;
int wmain()
{
SDL_Window* pWindow = NULL;
SDL_Renderer* pRenderer = NULL;
SDL_Surface* screen = NULL;
SDL_Init(SDL_INIT_EVERYTHING);
pWindow = SDL_CreateWindow(u8"æµè¯çªå£", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1920, 1080, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
pRenderer = SDL_CreateRenderer(pWindow, -1, 0);
screen = SDL_GetWindowSurface(pWindow);
//read 1.bmp 300x300 bgr
char ImageBuffer[300 * 300 * 3];
FILE* infile;
_wfopen_s(&infile, L"1.bmp", L"rb");
fseek(infile, 54, SEEK_SET);
fread(ImageBuffer, sizeof(ImageBuffer), 1, infile);
fclose(infile);
SDL_Surface* buffer = SDL_CreateRGBSurfaceFrom(ImageBuffer, 300, 300, 3 * 8, 300 * 3, 0x0000FF, 0x00FF00, 0xFF0000, 0x000000);
Image1 = SDL_CreateTextureFromSurface(pRenderer, buffer);
I1.x = I1.y = 20;I1.w = I1.h = 300;
//read 2.bmp 300x300 bgr
_wfopen_s(&infile, L"2.bmp", L"rb");
fseek(infile, 54, SEEK_SET);
fread(ImageBuffer, sizeof(ImageBuffer), 1, infile);
fclose(infile);
Image2 = SDL_CreateRGBSurfaceFrom(ImageBuffer, 300, 300, 3 * 8, 300 * 3, 0x0000FF, 0x00FF00, 0xFF0000, 0x000000);
I2.x = 350;I2.y = 20;I2.w = I2.h = 300;
SDL_Event event;
bool sQuit = false;
while (!sQuit)
{
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE)
{
sQuit = true;
}
if (event.key.keysym.sym == SDLK_1)
{
testshow = 1;
}
if (event.key.keysym.sym == SDLK_2)
{
testshow = 2;
}
break;
case SDL_QUIT:
sQuit = true;
break;
default:
break;
}
}
//SDL_RenderClear(pRenderer);
SDL_RenderCopy(pRenderer, Image1, NULL, &I1);//video card memory data
SDL_BlitSurface(Image2, NULL, screen, &I2);//random access memory data
//I want two methods for image render, but output image will flickering. could have only one.
SDL_RenderPresent(pRenderer);//video card render mode
SDL_UpdateWindowSurface(pWindow);//random access memory render mode
/*
switch (testshow)
{
case 1:
SDL_RenderClear(pRenderer);
SDL_RenderCopy(pRenderer, Image1, NULL, &I1);
SDL_RenderPresent(pRenderer);
break;
case 2:
SDL_BlitSurface(Image2, NULL, screen, &I2);
SDL_UpdateWindowSurface(pWindow);
break;
}
*/
}
SDL_Quit();
}
I want "SDL_RenderPresent" and "SDL_UpdateWindowSurface" in the same screen.
For example, âSDL_Textureâ is normal image, âSDL_Surfaceâ is Chinese characters. about render font, render âSDL_Surfaceâ,Instead of from âSDL_Surfaceâ to âSDL_Textureâ.