本文整理汇总了C++中SDL_CreateRenderer函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_CreateRenderer函数的具体用法?C++ SDL_CreateRenderer怎么用?C++ SDL_CreateRenderer使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_CreateRenderer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int, char**) {
// This section is the initialization for SDL2
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
logSDLError(std::cout, "SDL_Init");
return 1;
}
SDL_Window *window = SDL_CreateWindow("Moving Window", 100, 100, 1440, 810, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
if (window == nullptr) {
logSDLError(std::cout, "CreateWindow");
SDL_Quit();
return 1;
}
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (renderer == nullptr) {
logSDLError(std::cout, "CreateRenderer");
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
// Initialize all the Images and Texts Pointers
const std::string resPath = getResourcePath("FeedbackDisplay");
SDL_Texture *instruction = loadTexture(resPath + "instruction.png", renderer);
SDL_Texture *trial_background = loadTexture(resPath + "background.png", renderer);
SDL_Texture *background = loadTexture(resPath + "SyncStart.png", renderer);
SDL_Texture *background2 = loadTexture(resPath + "SyncEnd.png", renderer);
SDL_Texture *instruction2 = loadTexture(resPath + "instruction2.png", renderer);
SDL_Texture *sphere = loadTexture(resPath + "sphere.png", renderer);
SDL_Texture *Target = loadTexture(resPath + "Target.png", renderer);
SDL_Texture *sphere2 = loadTexture(resPath + "sphere2.png", renderer);
SDL_Texture *Target2 = loadTexture(resPath + "Target2.png", renderer);
SDL_Texture *trialStart = loadTexture(resPath + "trialStart.png", renderer);
SDL_Texture *trialEnd = loadTexture(resPath + "trialEnd.png", renderer);
SDL_Event event;
if (background == nullptr || background2 == nullptr || sphere == nullptr || instruction2 == nullptr || Target == nullptr || sphere2 == nullptr || Target2 == nullptr ||
trialStart == nullptr || trialEnd == nullptr || instruction == nullptr || trial_background == nullptr )
{
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
SDL_DestroyTexture(background);
SDL_DestroyTexture(trial_background);
SDL_DestroyTexture(instruction);
SDL_DestroyTexture(sphere);
SDL_DestroyTexture(background2);
SDL_DestroyTexture(sphere2);
SDL_DestroyTexture(Target2);
SDL_DestroyTexture(Target);
SDL_DestroyTexture(instruction2);
SDL_Quit();
SDL_Quit();
return 1;
}
SDL_GetWindowSize(window, &SCREEN_WIDTH, &SCREEN_HEIGHT);
// Wait for Synchronization between OpenBCI and Feedback Display
SDL_RenderClear(renderer);
renderTexture(background, renderer, (SCREEN_WIDTH - SCREEN_HEIGHT) / 2, 0, SCREEN_HEIGHT, SCREEN_HEIGHT);
SDL_RenderPresent(renderer);
// Obtain the timer as well as the logging files
const std::string Feature1 = getResourcePath("FIFO") + "X_Direction.txt";
const std::string Feature2 = getResourcePath("FIFO") + "Y_Direction.txt";
const std::string Trial_Info = getResourcePath("FIFO") + "Trial_Information.txt";
const std::string Trigger_Log = getResourcePath("FIFO") + "Trigger_Log.txt";
const std::string Feedback = getResourcePath("FIFO") + "Feedback_Log_0.txt";
Sync_Send(Feedback, "Timer on");
Sync_Wait(Trigger_Log, "All Set", "ALL FINISH", event);
SDL_RenderClear(renderer);
renderTexture(background2, renderer, (SCREEN_WIDTH - SCREEN_HEIGHT) / 2, 0, SCREEN_HEIGHT, SCREEN_HEIGHT);
SDL_RenderPresent(renderer);
// flag used to stop the program execution
bool Next_Trial, Finishing;
Finishing = false;
// Obtain Screen Size, Create position values for objects
Position Centroid, Ball, Goal;
const int SPHERE_SIZE = SCREEN_HEIGHT / 10;
const int TARGET_WIDTH = SCREEN_HEIGHT / 10;
const int TARGET_HEIGHT = TARGET_WIDTH;
int Margin;
Centroid.Set(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 0, 0);
std::string Previous_X, Previous_Y, Current_X, Current_Y;
Feature X_Direction,Y_Direction;
X_Direction.Set(1,0);
Y_Direction.Set(1,0);
// Maintain the Field of movement within Square
if (SCREEN_HEIGHT < SCREEN_WIDTH)
Margin = (SCREEN_WIDTH - SCREEN_HEIGHT) / 2;
else
Margin = 0;
// Calibration
if (!Sync_Wait(Trigger_Log, "Calibration On", "ALL FINISH", event)) {
Sync_Send(Feedback,"Display End");
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
//.........这里部分代码省略.........
示例2: main
int main(void)
{
if(SDL_Init(SDL_INIT_VIDEO) != 0)
{
fprintf(stderr, "SDL_Init( Error : %s\n", SDL_GetError());
exit(1);
}
SDL_Window *win = SDL_CreateWindow("Hello World !", 100, 100, 700, 700, SDL_WINDOW_SHOWN);
if(win == NULL)
{
fprintf(stderr, "SDL_CreateWindow Error : %s\n", SDL_GetError());
exit(1);
}
SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if(ren == NULL)
{
SDL_DestroyWindow(win);
fprintf(stderr, "SDL_CreateRenderer Error: %s\n", SDL_GetError());
SDL_Quit();
exit(1);
}
SDL_Surface *bmp = SDL_LoadBMP("../media/wtf.bmp");
if(bmp == NULL)
{
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
fprintf(stderr, "SDL_LoadBMP Error: %s \n", SDL_GetError());
SDL_Quit();
exit(1);
}
SDL_Texture *tex = SDL_CreateTextureFromSurface(ren, bmp);
SDL_FreeSurface(bmp);
if(tex == NULL)
{
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
fprintf(stderr, "SDL_CreateTextureFromSurface Error :%s \n", SDL_GetError());
SDL_Quit();
exit(1);
}
if(Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) == -1)
return false;
SDL_RenderClear(ren);
SDL_RenderCopy(ren, tex, NULL, NULL);
SDL_RenderPresent(ren);
Mix_Music *music = NULL;
SDL_Event event;
bool running = false;
int x = 0, y = 0;
bool re = true;
while(!running)
{
if(!re)
exit(0);
// execl("finalProject", NULL);
if(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT) running = true;
if(event.type == SDL_MOUSEMOTION)
{
SDL_GetMouseState(&x, &y);
if((x >= 66) && (x <= 550) && (y >= 638) && (y <= 700))
{
re = true;
}
/*first sqr
x - 66 y - 638 x - 550 y 638
x - 66 y - 700 x - 550 y - 700
*/
else if((x >= 550) && (x <= 582) && (y >= 536) && (y <= 800))
{
re = true;
}
/*second
x - 550 y - 536 x 582 y 536
x - 550 y - 700 x 582 y 700
*/
else if((x >= 66) && (x <= 550) && (y >= 536) && (y <= 590))
{
//.........这里部分代码省略.........
示例3: main
int main()
{
SDL_Init(SDL_INIT_VIDEO);
// SDL Initialization
SDL_Window *window = SDL_CreateWindow("Roguelike",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH, SCREEN_HEIGHT,
0);//SDL_WINDOW_FULLSCREEN_DESKTOP);
SDL_Renderer *renderer = SDL_CreateRenderer(window, 0, SDL_RENDERER_SOFTWARE);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
SDL_Texture *screen = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_STREAMING,
SCREEN_WIDTH, SCREEN_HEIGHT);
// Set up our console
PT_Console *console = PT_ConsoleInit(SCREEN_WIDTH, SCREEN_HEIGHT,
GRID_ROW_COUNT, GRID_COL_COUNT);
PT_ConsoleSetBitmapFont(console, "./terminal16x16.png", 0, 16, 16);
game_init();
// Main game loop
u32 delayTime = 1000 / FPS_LIMIT;
u32 frameStart, frameTime = 0;
i32 spareTime = 0;
bool done = false;
while (!done) {
frameStart = SDL_GetTicks();
// Handle all events in the queue
SDL_Event event;
while (SDL_PollEvent(&event) != 0) {
if (event.type == SDL_QUIT) {
done = true;
break;
}
if (event.type == SDL_KEYDOWN) {
SDL_Keycode key = event.key.keysym.sym;
switch (key) {
case SDLK_UP:
object_move(player, 0, -1);
break;
case SDLK_DOWN:
object_move(player, 0, 1);
break;
case SDLK_LEFT:
object_move(player, -1, 0);
break;
case SDLK_RIGHT:
object_move(player, 1, 0);
break;
default:
break;
}
}
}
// Render the current frame
render_all(renderer, screen, console);
// Avoid pegging the CPU at 100% by sleeping for a bit
frameTime = SDL_GetTicks() - frameStart;
spareTime = delayTime - frameTime;
if (spareTime > 0) {
SDL_Delay(spareTime);
}
}
// Clean up
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
示例4: Mix_OpenAudio
bool Game::Init(const char* title, int xpos, int ypos, int width, int height,
int flags) {
// attempt to initialize SDL
if (SDL_Init(SDL_INIT_EVERYTHING) == 0) {
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4097);
std::cout << "SDL init success\n";
// init the window
m_pWindow = SDL_CreateWindow(title, xpos, ypos, width, height, flags);
if (m_pWindow != 0) // window init success
{
std::cout << "window creation success\n";
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0);
if (m_pRenderer != 0) // renderer init success
{
std::cout << "renderer creation success\n";
SDL_SetRenderDrawColor(m_pRenderer, 255, 255, 255, 255);
} else {
std::cout << "renderer init fail\n";
return false; // renderer init fail
}
} else {
std::cout << "window init fail\n";
return false; // window init fail
}
} else {
std::cout << "SDL init fail\n";
return false; // SDL init fail
}
std::cout << "init success\n";
m_bRunning = true; // everything inited successfully,
// start the main loop
//initial game State
SoundsBank::sound = new SoundsBank();
SoundsBank::sound->initSoundEffect("sounds/hover.wav");
SoundsBank::sound->initSoundEffect("sounds/connect.wav");
SoundsBank::sound->initSoundEffect("sounds/button-24.wav");
SoundsBank::sound->initSoundEffect("sounds/no_time.wav");
SoundsBank::sound->initMusic("sounds/removeCards.mp3");
StateManager::stateMachine = new StateManager();
StateManager::stateMachine->setCurrentGameStates(MENU);
Timer::g_Timer = new Timer();
StartMenu.InitSatistics(m_pRenderer);
StartMenu.Init(m_pRenderer);
StartMenu.InitRules(m_pRenderer);
m_buttonsMenu.Init(m_pRenderer);
for (int iter = 0; iter < 5; iter++) {
m_buttonsMenu.setSource(iter * 232, 0, 232, 52);
m_buttonsMenu.setDestination(100, (250 + 60 * iter), 260, 50);
m_buttonSet.push_back(m_buttonsMenu);
}
PlayButton = m_buttonSet.at(0);
PlayButton.setSource(0, 0, 232, 52);
PlayButton.setDestination(410, 684, 240, 60);
m_buttonSet.at(4).setDestination(25, 699, 150, 45);
// Buttons MenuButton;
texture.Init(m_pRenderer);
m_cardLogic.Init(m_pRenderer);
txt.Set(450, 60, 60, 45, " ");
txt.setTextColor(255, 255, 0, 255);
level.Set(756, 60, 60, 45, " ");
level.setTextColor(255, 255, 0, 255);
// **************
bet.Set(920, 690, 60, 44, " ");
bet.setTextColor(255, 255, 0, 255);
bet.IntToTextMessage(5);
credit.Set(270, 690, 60, 45, " ");
credit.setTextColor(255, 255, 0, 255);
profit.Set(756, 690, 60, 44, " ");
profit.setTextColor(255, 255, 0, 255);
m_stat.createFile();
m_Recovery.createRecoverFile();
return true;
}/*end of Init*/
示例5: main
int main(int argc, char **argv){
if(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG != IMG_INIT_PNG){
err_msg("IMG_INIT");
return 1;
}
if (SDL_Init(SDL_INIT_EVERYTHING)){
//std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;
err_msg("SDL_Init");
return 1;
}
SDL_Window *win = SDL_CreateWindow("Hello World!", 100, 100, SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_SHOWN);
if (!win){
//std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
err_msg("CreateWindow");
return 1;
}
SDL_Renderer *ren = SDL_CreateRenderer(win, -1,
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (!ren){
//std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
err_msg("CreateRenderer");
return 1;
}
SDL_Texture *background = load_texture("background.png", ren);
SDL_Texture *image = load_texture("image.png", ren);
if(!((long)background & (long)image)){
err_msg("Load Images");
return 1;
}
SDL_RenderClear(ren);
int w, h;
SDL_QueryTexture(background, NULL, NULL, &w, &h);
/*for(int i = 0; i < 4; i++){
render_texture(background, ren, (i & 1) * w, ((i >> 1) & 1) * h);
}*/
int tile_x = SCREEN_WIDTH / TILE_SIZE;
int tile_y = SCREEN_HEIGHT / TILE_SIZE;
for(int i = 0; i < tile_x * tile_y; i++){
int x = i % tile_x;
int y = i / tile_x;
render_texture(background, ren, x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE);
}
int iW, iH;
SDL_QueryTexture(image, NULL, NULL, &iW, &iH);
int x = SCREEN_WIDTH / 2 - iW / 2;
int y = SCREEN_HEIGHT / 2 - iH / 2;
render_texture(image, ren, x, y);
SDL_RenderPresent(ren);
SDL_Delay(2000);
SDL_DestroyTexture(background);
SDL_DestroyTexture(image);
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
SDL_Quit();
}
示例6: strcpy
//-----------------------------------------------------------------
// Game Engine General Methods
//-----------------------------------------------------------------
bool GameEngine::Initialize(const char* szTitle, const char* szIcon, int iWidth, int iHeight)
{
// Set the member variables for the game engine
m_pGameEngine = this;
m_hWindow = NULL;
if (strlen(szTitle) > 0)
strcpy(m_szTitle, szTitle);
if (strlen(szTitle) > 0)
strcpy(m_szIcon, szIcon);
m_iWidth = iWidth;
m_iHeight = iHeight;
m_iFrameDelay = 50; // 20 FPS default
m_bSleep = true;
SDL_Init(SDL_INIT_VIDEO |
SDL_INIT_AUDIO |
SDL_INIT_GAMECONTROLLER); // Initialize SDL2
//Initialize SDL2 Mixer
if (Mix_OpenAudio(22050, AUDIO_U8, 2, 512) < 0){
std::cout << "Unable to init sound engine: " << SDL_GetError() << std::endl;
}
//Initialize SDL2 TTF
if(TTF_Init()==-1) {
std::cout << "TTF_Init: " << TTF_GetError() << std::endl;
exit(EXIT_FAILURE);
}
//create the window
m_hWindow = SDL_CreateWindow(m_szTitle, // window title
SDL_WINDOWPOS_UNDEFINED, // initial x position
SDL_WINDOWPOS_UNDEFINED, // initial y position
m_iWidth, // width, in pixels
m_iHeight, // height, in pixels
SDL_RENDERER_ACCELERATED |
SDL_RENDERER_PRESENTVSYNC // flags
);
if (!m_hWindow)
return false;
//set the window icon from the .ico file
// The icon is attached to the window pointer
SDL_Surface *icone_surface = IMG_Load(szIcon);
SDL_SetWindowIcon(m_hWindow, icone_surface);
//the surface containing the icon pixel data is no longer required.
SDL_FreeSurface(icone_surface);
//Create a Renderer
m_renderer = SDL_CreateRenderer(m_hWindow,
0,
SDL_RENDERER_ACCELERATED |
SDL_RENDERER_PRESENTVSYNC);
//Clear the screen
SDL_SetRenderDrawColor(m_renderer, 255, 255, 255, 255);
SDL_RenderClear(m_renderer);
SDL_RenderPresent(m_renderer);
return true;
}
示例7: main
int
main(
int argc,
char ** argv
) {
int width = 600;
int height = 600;
bool running = true;
float (* state_current)[NVER][NHOR] = &state_buffer_a;
float (* state_next)[NVER][NHOR] = &state_buffer_b;
float (* dstate_current)[NVER][NHOR] = &dstate_buffer_a;
float (* dstate_next)[NVER][NHOR] = &dstate_buffer_b;
float (* state_swap_temp)[NVER][NHOR];
int mouse_x, mouse_y;
bool ismousedown = false;
SDL_Event event;
SDL_Window * window = SDL_CreateWindow(
"CO",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
width,
height,
SDL_WINDOW_SHOWN
);
SDL_Renderer * renderer = SDL_CreateRenderer(
window,
-1,
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC
);
SDL_SetRenderDrawBlendMode(
renderer,
SDL_BLENDMODE_BLEND
);
int dt, now, tick_begin = SDL_GetTicks();
init(state_current, dstate_current);
draw(renderer, width, height, state_current);
SDL_RenderPresent(renderer);
for (;;) {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
running = false;
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE) {
running = false;
}
break;
case SDL_MOUSEBUTTONDOWN:
ismousedown = true;
break;
case SDL_MOUSEBUTTONUP:
ismousedown = false;
break;
default:
break;
}
}
if (ismousedown) {
SDL_GetMouseState(&mouse_x, &mouse_y);
input(state_current, dstate_current,
mouse_x * NHOR / width, mouse_y * NVER / height);
}
if (!running) {
break;
}
now = SDL_GetTicks();
if ((dt = now - tick_begin) > DT) {
tick_begin = now;
update(state_current, state_next, dstate_current, dstate_next);
swap(&state_current, &state_next);
swap(&dstate_current, &dstate_next);
draw(renderer, width, height, state_current);
SDL_RenderPresent(renderer);
}
}
SDL_DestroyRenderer(renderer);
SDL_Quit();
}
示例8: WinMain
// WINDOWS MAIN FUNCTION
// hInst = current instance of the program
// hPrevInst = previous instance which is not used anymore.
// cmdLine = holds command line arguments to be passed in to the program
// cmdShow = holds an integer to specify if we want to show this window.
int CALLBACK WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR cmdLine, int cmdShow)
{
WNDCLASS wc = {0};
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.hInstance = hInst;
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = wndClassName;
wc.hCursor = 0; //TODO: Add cursors and icons to this program.
wc.hIcon = 0;
wc.lpfnWndProc = (WNDPROC)wndProc;
RegisterClass(&wc);
HWND window = CreateWindow(wndClassName, wndTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
wndWidth, wndHeight,
0, 0, hInst, 0);
if(window)
{
ShowWindow(window, SW_SHOW);
UpdateWindow(window);
// NOTE: Initializing SDL
if(SDL_Init(SDL_INIT_VIDEO) != 0 )
{
DestroyWindow(window);
return -2;
}
IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG);
sdlWindow = SDL_CreateWindowFrom((void*)window);
char error[MAX_PATH];
stringCopy(error, SDL_GetError());
OutputDebugStringA(error);
if(!sdlWindow)
{
SDL_Quit();
DestroyWindow(window);
return -3;
}
renderer = SDL_CreateRenderer(sdlWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if(!renderer)
{
SDL_DestroyWindow(sdlWindow);
SDL_Quit();
DestroyWindow(window);
return -4;
}
i32 RefreshRate = 0;
HDC dc = GetDC(window);
i32 winRefreshRate = GetDeviceCaps(dc, VREFRESH);
if( winRefreshRate > 1 )
{
RefreshRate = winRefreshRate / 2;
}
else
{
RefreshRate = 30;
}
r32 targetSecsPerFrame = 1.0f / RefreshRate;
GameMemory memory = {};
memory.permanentSize = Megabytes(64);
memory.transientSize = Megabytes(64);
memory.totalSize = memory.permanentSize + memory.transientSize;
gameMemoryBlock = VirtualAlloc( 0, memory.totalSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if(!gameMemoryBlock)
{
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(sdlWindow);
SDL_Quit();
DestroyWindow(window);
return -5;
}
memory.permanentBlock = gameMemoryBlock;
memory.transientBlock = (i8*)gameMemoryBlock + memory.permanentSize;
memory.readEntireFile = ReadEntireFile;
memory.freeFile = FreeFile;
memory.writeEntireFile = WriteEntireFile;
Win32Dims windowDims = GetWindowDimensions(window);
//.........这里部分代码省略.........
示例9: main
int main(void)
{
SDL_Window *wind;
SDL_Renderer *ren;
VIEW view={0, 400, 0, 400};
WIN win={-1.0, 1.0, -1.0, 1.0};
int n,i,j;
int x[DIM],y[DIM];
float step,s,c,scx,scy;
float x0,y0,xi,yi;
clock_t start, endt;
if(SDL_Init(SDL_INIT_VIDEO)<0)
{
fprintf(stderr,"Couldn't init video: %s\n",SDL_GetError());
return(1);
}
wind= SDL_CreateWindow("Polygonf", 100, 100,view.vxmax,view.vymax, SDL_WINDOW_SHOWN);
if(wind==NULL){
fprintf(stderr,"SDL_CreateWindow Error: %s\n",SDL_GetError());
SDL_Quit();
return 1;
}
ren = SDL_CreateRenderer(wind, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (ren == NULL){
SDL_DestroyWindow(wind);
fprintf(stderr,"SDL_CreateRenderer Error: %s\n",SDL_GetError());
SDL_Quit();
return 1;
}
SDL_SetRenderDrawColor(ren, 50, 50, 50, 255);
SDL_RenderClear(ren);
SDL_RenderPresent(ren);
scx=(view.vxmax-view.vxmin)/(win.wxmax-win.wxmin);
scy=(view.vymax-view.vymin)/(win.wymax-win.wymin);
printf("\nDisegno di un poligono regolare: \n");
printf("Dai il numero di vertici: \n");
scanf("%d",&n);
step=6.28/n;
s=sin(step);
c=cos(step);
x0=1.0;
y0=0.0;
wind_view(x0,y0,&x[0],&y[0],scx,scy,&view,&win);
for (i=0; i<=n; i++)
{
xi=x0*c-y0*s;
yi=x0*s+y0*c;
wind_view(xi,yi,&x[i],&y[i],scx,scy,&view,&win);
x0=xi;
y0=yi;
}
start=clock();
/* disegna poligono */
SDL_SetRenderDrawColor(ren, 255, 255, 255, 255);
SDL_RenderDrawLine(ren, x[n-1], y[n-1], x[0], y[0]);
for (i=0; i<n-1; i++)
SDL_RenderDrawLine(ren, x[i], y[i], x[i+1], y[i+1]);
SDL_RenderPresent(ren);
#ifdef DEBUG
/* disegno artistico: definire DEBUG nel Makefile*/
SDL_SetRenderDrawColor(ren, 255, 255, 0, 255);
for (i=0; i<n; i++)
for (j=i+1; j<n; j++)
SDL_RenderDrawLine(ren, x[i], y[i], x[j], y[j]);
SDL_RenderPresent(ren);
#endif
endt=clock();
printf("\n Tempo: %f \n", (double)(endt-start)/CLOCKS_PER_SEC);
press();
SDL_Quit();
return(0);
}
示例10: main
int main(int argc, char **argv)
{
mtc_init("planet", 7);
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
mtc_err("sdl init error: %s", SDL_GetError());
return 1;
}
if (TTF_Init() == -1) {
mtc_err("ttf init error: %s", TTF_GetError());
return 1;
}
SDL_Window *win = SDL_CreateWindow("Hello OpenGL!",
100, 100, WIN_WIDTH, WIN_HEIGHT, SDL_WINDOW_SHOWN);
if (!win) {
mtc_err("SDL_CreateWindow Error: %s", SDL_GetError());
return 1;
}
m_render = SDL_CreateRenderer(win, -1,
SDL_RENDERER_ACCELERATED |
SDL_RENDERER_PRESENTVSYNC);
if (!m_render) {
mtc_err("SDL_CreateRenderer Error: %s", SDL_GetError());
return 1;
}
set_glversion();
gl_info();
glLoadIdentity();
glOrtho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0);
glEnable(GL_DEPTH_TEST);
glEnable( GL_TEXTURE_2D );
glDepthFunc(GL_LEQUAL);
//glCullFace(GL_BACK);
//glFrontFace(GL_CCW);
//glEnable(GL_CULL_FACE);
GLuint etex = LoadTextureRAW("earth.raw");
if (etex == 0) {
mtc_err("Load texture failure");
return 1;
}
mutil_create_earth(5, 0, 0, 0);
SDL_Event e;
bool quit = false;
while (!quit) {
while (SDL_PollEvent(&e)) {
if (e.type == SDL_KEYDOWN) {
switch (e.key.keysym.sym) {
case SDLK_ESCAPE:
quit = true;
break;
}
}
}
rend_sun();
mutil_rend_earth(etex);
SDL_RenderPresent(m_render);
}
SDL_DestroyRenderer(m_render);
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}
示例11: CreateMainFrame
void CreateMainFrame(FrameCreationCallback inOnFrame, int inWidth, int inHeight, unsigned int inFlags, const char *inTitle, Surface *inIcon)
{
bool fullscreen = (inFlags & wfFullScreen) != 0;
bool opengl = (inFlags & wfHardware) != 0;
bool resizable = (inFlags & wfResizable) != 0;
bool borderless = (inFlags & wfBorderless) != 0;
bool vsync = (inFlags & wfVSync) != 0;
sgShaderFlags = (inFlags & (wfAllowShaders|wfRequireShaders) );
Rect r(100,100,inWidth,inHeight);
int err = InitSDL();
if (err == -1)
{
fprintf(stderr,"Could not initialize SDL : %s\n", SDL_GetError());
inOnFrame(0);
}
//SDL_EnableUNICODE(1);
//SDL_EnableKeyRepeat(500,30);
//gSDLIsInit = true;
#ifdef NME_MIXER
#ifdef HX_WINDOWS
int chunksize = 2048;
#else
int chunksize = 4096;
#endif
int frequency = 44100;
//int frequency = MIX_DEFAULT_FREQUENCY //22050
//The default frequency would have less latency, but is incompatible with the average MP3 file
if (Mix_OpenAudio(frequency, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, chunksize) != 0)
{
fprintf(stderr,"Could not open sound: %s\n", Mix_GetError());
gSDLIsInit = false;
}
#endif
//const SDL_VideoInfo *info = SDL_GetVideoInfo();
//sgDesktopWidth = info->current_w;
//sgDesktopHeight = info->current_h;
//#ifdef RASPBERRYPI
//sdl_flags = SDL_SWSURFACE;
//if (opengl)
//fullscreen = true;
//#else
//sdl_flags = SDL_HWSURFACE;
//#endif
//int use_w = fullscreen ? 0 : inWidth;
//int use_h = fullscreen ? 0 : inHeight;
int windowFlags = 0;
if (opengl) windowFlags |= SDL_WINDOW_OPENGL;
if (resizable) windowFlags |= SDL_WINDOW_RESIZABLE;
if (borderless) windowFlags |= SDL_WINDOW_BORDERLESS;
if (fullscreen) windowFlags |= SDL_WINDOW_FULLSCREEN; //SDL_WINDOW_FULLSCREEN_DESKTOP;
SDL_Window *window = SDL_CreateWindow (inTitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, fullscreen ? 0 : inWidth, fullscreen ? 0 : inHeight, windowFlags);
if (!window) return;
int renderFlags = 0;
if (opengl) renderFlags |= SDL_RENDERER_ACCELERATED;
if (vsync) renderFlags |= SDL_RENDERER_PRESENTVSYNC;
SDL_Renderer *renderer = SDL_CreateRenderer (window, -1, renderFlags);
if (!renderer && opengl) {
opengl = false;
renderFlags &= ~SDL_RENDERER_ACCELERATED;
renderer = SDL_CreateRenderer (window, -1, renderFlags);
}
if (!renderer) return;
if (opengl) {
//SDL_GL_SetAttribute();
// set attributes?
}
/*#if defined(IPHONE) || defined(BLACKBERRY) || defined(EMSCRIPTEN)
sdl_flags |= SDL_NOFRAME;
#else
if (inIcon)
{
SDL_Surface *sdl = SurfaceToSDL(inIcon);
//.........这里部分代码省略.........
示例12: main
int
main(int argc, char *argv[])
{
int index; /* index of last key we pushed in the bitmap font */
SDL_Window *window;
SDL_Event event; /* last event received */
SDL_Keymod mod; /* key modifiers of last key we pushed */
SDL_Scancode scancode; /* scancode of last key we pushed */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("Error initializing SDL: %s", SDL_GetError());
}
/* create window */
window = SDL_CreateWindow("iPhone keyboard test", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
/* create renderer */
renderer = SDL_CreateRenderer(window, -1, 0);
/* load up our font */
loadFont();
/* draw the background, we'll just paint over it */
SDL_SetRenderDrawColor(renderer, bg_color.r, bg_color.g, bg_color.b,
bg_color.unused);
SDL_RenderFillRect(renderer, NULL);
SDL_RenderPresent(renderer);
int done = 0;
/* loop till we get SDL_Quit */
while (SDL_WaitEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
done = 1;
break;
case SDL_KEYDOWN:
index = keyToIndex(event.key.keysym);
scancode = event.key.keysym.scancode;
mod = event.key.keysym.mod;
if (scancode == SDL_SCANCODE_DELETE) {
/* if user hit delete, delete the last character */
backspace();
lastCharWasColon = 0;
} else if (lastCharWasColon && scancode == SDL_SCANCODE_0
&& (mod & KMOD_SHIFT)) {
/* if our last key was a colon and this one is a close paren, the make a hoppy face */
backspace();
drawIndex(32); /* index for happy face */
numChars++;
drawCursor();
lastCharWasColon = 0;
} else if (index != -1) {
/* if we aren't doing a happy face, then just draw the normal character */
drawIndex(index);
numChars++;
drawCursor();
lastCharWasColon =
(event.key.keysym.scancode == SDL_SCANCODE_SEMICOLON
&& (event.key.keysym.mod & KMOD_SHIFT));
}
/* check if the key was a colon */
/* draw our updates to the screen */
SDL_RenderPresent(renderer);
break;
case SDL_MOUSEBUTTONUP:
/* mouse up toggles onscreen keyboard visibility */
if (SDL_IsTextInputActive()) {
SDL_StopTextInput();
} else {
SDL_StartTextInput();
}
break;
}
}
cleanup();
return 0;
}
示例13: main
int main(int argc, char* args[]) {
// This will be the window we'll be rendering to
SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL;
TTF_Font *font;
SDL_Texture *sheet = NULL;
Text text;
init_sprites();
event_init();
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("SDL could not initialize! SDL_ERROR: %s\n", SDL_GetError());
} else {
//if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, 1)) {
// printf("Warning: Linear texture filtering not enabled");
//}
window = SDL_CreateWindow("Piggle",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH,
SCREEN_HEIGHT,
SDL_WINDOW_SHOWN);
if (window == NULL) {
printf("Window could not be created! SDL_Error: %s\n",
SDL_GetError());
} else {
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (renderer == NULL) {
printf("Renderer couldn't be created. Shit's fucked, becuase %s"
", dude.\n", SDL_GetError());
} else {
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
int imgFlags = IMG_INIT_PNG;
if (!(IMG_Init(imgFlags) & imgFlags)) {
printf("SDL_image couldn't be initialized. Shit's fucked, "
"because %s, dude.\n", IMG_GetError());
}
if (TTF_Init() == -1) {
printf("SDL_ttf couldn't initialize. Shit's fucked, becuase"
" %s, dude.\n", TTF_GetError());
}
}
font = TTF_OpenFont("DroidSansMono.ttf", 16);
if (font == NULL) {
printf("Failed to load lazy font. Shit's fucked, because %s, "
"dude.", TTF_GetError());
}
sheet = loadTexture("img/sprites.png", renderer);
// When quit is set to true, we'll stop running
bool quit = false;
piggle_scene_over = false;
// Event handler
SDL_Event sdl_event;
// Set the current scene to the start scene
piggle_scene_update = start_scene_update;
while (!quit) {
timer_start();
EventList events = EventList_new();
while (SDL_PollEvent(&sdl_event) != 0) {
Event event;
// If the user presses that little "x"
if (sdl_event.type == SDL_QUIT) {
quit = true;
event.type = QUIT;
} else if (sdl_event.type == SDL_KEYDOWN) {
event.type = KEYDOWN;
int key = sdl_event.key.keysym.sym;
event.value = event_value_from_key(key);
} else if (sdl_event.type == SDL_KEYUP) {
event.type = KEYUP;
int key = sdl_event.key.keysym.sym;
event.value = event_value_from_key(key);
} else {
continue;
}
events.add_event(&events, event);
}
SDL_RenderClear(renderer);
DrawActionList actions = DrawActionList_new();
piggle_scene_update(&events, &actions);
events.destroy(&events);
int i;
for (i = 0; i < actions.length; i++) {
DrawAction action = actions.actions[i];
if (action.type == SPRITE) {
SDL_Rect *sprite = &sprites[action.sprite];
SDL_Rect dest;
dest.x = action.x;
dest.y = action.y;
dest.w = sprite->w;
dest.h = sprite->h;
//.........这里部分代码省略.........
示例14: wmain
int
wmain(void) {
uint64 PerfCountFrequency = SDL_GetPerformanceFrequency();
SDL_Event Event;
SDL_Window *Window;
SDL_Renderer *Renderer;
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC) != 0) {
char *Error = "Could not initialize SDL: %s\n";
printf(Error, SDL_GetError());
return -1;
}
atexit(SDL_Quit);
int WindowWidth = 1300;
int WindowHeight = 870;
int BytesPerPixel = 4;
Window = SDL_CreateWindow("Echelon",
30, 30,
WindowWidth, WindowHeight,
SDL_WINDOW_RESIZABLE);
if(Window) {
Renderer = SDL_CreateRenderer(Window, -1, 0);
if(Renderer) {
GlobalRunning = true;
window_dimensions Dimensions = SDLGetWindowDimensions(Window);
SDLCreateNewTexture(&GlobalBuffer,
Renderer,
Dimensions.Width, Dimensions.Height,
BytesPerPixel);
uint64 LastCounter = SDL_GetPerformanceCounter();
uint64 LastCycleCount = __rdtsc();
real64 DebugTimer = 0;
real64 FPSTimer = 0;
real64 UpdateTimer = 0;
uint32 FPS = 0;
uint32 UPS = 0;
keyboard_input KeyboardInput = {};
gamepad_input GamePadInput = {};
game_code Game = LoadGameCode();
game_memory GameMemory = {0};
GameMemory.IsInitialized = false;
GameMemory.PlayRumble = SDLPlayRumble;
GameMemory.WindowDimensions = SDLGetWindowDimensions(Window);
GameMemory.PermanentStorageSize = Gigabytes(4);
GameMemory.PermanentStorage = VirtualAlloc(0,
GameMemory.PermanentStorageSize,
MEM_COMMIT, PAGE_READWRITE);
//Assert((GameMemory.PermanentStorageSize));
GameMemory.TransientStorageSize = Megabytes(4);
GameMemory.TransientStorage = VirtualAlloc(0,
GameMemory.TransientStorageSize,
MEM_COMMIT, PAGE_READWRITE);
//Assert((GameMemory.TransientStorageSize));
Game.GameInit(&GameMemory);
while(GlobalRunning) {
// NOTE(Redab): This needs to while loop because we need
// to handle events as long as they are available.
while(SDL_PollEvent(&Event)) {
SDLHandleEvent(&Event, &Dimensions);
SDLHandleUserInput(&Event, &Game, &GameMemory, &KeyboardInput, &GamePadInput);
}
uint64 EndCycleCount = __rdtsc();
uint64 EndCounter = SDL_GetPerformanceCounter();
uint64 CounterElapsed = EndCounter - LastCounter;
uint64 CyclesElapsed = EndCycleCount - LastCycleCount;
// NOTE(Redab): CounterElapsed Contains the number of
// clock cycles since last check. So we need to divide
// this by the number of cycles per second which we
// have in PerCountFrequency. Multiplied by 1000 to
// get milliseconds.
real64 SecondsPerFrame = ((real64)CounterElapsed / (real64)PerfCountFrequency);
real64 MSPerFrame = SecondsPerFrame * 1000.0f;
real64 KCPF = ((real64)CyclesElapsed / (1000.0f));
FPSTimer += MSPerFrame;
UpdateTimer += MSPerFrame;
DebugTimer += MSPerFrame;
if(UpdateTimer >= (1000.0f / 60.0f)) {
GameMemory.WindowDimensions = Dimensions;
//.........这里部分代码省略.........
示例15: iniciar
int iniciar( SDL_Window** janela, SDL_Renderer** render)
{
bool sucesso = true;
//Inicia o SDL
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
{
printf("En: SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
printf("Pt: SDL nao pode ser iniciado! Err o: %s\n", SDL_GetError() );
sucesso = false;
}
else
{
//Adquirindo as medidas da tela
//Variavel que armazena as medidas da tela e a frequencia
SDL_DisplayMode telaAtual;
//Chamando a função para definir as propriedades da tela atual (retorna 0 se for sucesso)
if(SDL_GetCurrentDisplayMode(0, &telaAtual) != 0)
{
//Em caso de erro
printf("En: Could not get display mode for video display : %s", SDL_GetError());
printf("Pt: Nao foi possivel obter um monitor e suas propriedades : %s", SDL_GetError());
sucesso = false;
}
else
{
int alturaTela =28*telaAtual.h/34;
int larguraTela = 31*telaAtual.h/34;
ofstream out;
out.open("config.txt");
out<<"altura = "<< alturaTela <<"\n"<<"largura = "<< larguraTela;
//out<<"altura = "<<395<<"\n"<<"largura = "<< 487;
out.close();
*janela = SDL_CreateWindow( nome.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, larguraTela , alturaTela, SDL_WINDOW_SHOWN );
//*janela = SDL_CreateWindow( nome.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 487, 395, SDL_WINDOW_SHOWN );
if(*janela == NULL)
{
printf( "En: Window could not be created! SDL_Error: %s\n", SDL_GetError() );
printf( "Pt: Não foi possivel criar a janela! Erro: %s\n", SDL_GetError() );
sucesso = false;
}
else
{
*render = SDL_CreateRenderer( *janela, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
//Verificando se render foi inicializada com sucesso
if(*render == NULL)
{
printf( "En: Render could not be created! SDL Error: %s\n", SDL_GetError() );
printf( "Pt: Não foi possivel criar a Renderer! Erro: %s\n", SDL_GetError() );
sucesso = false ;
}
else
{
//Se a render tiver sido iniciada corretamente, definir a cor dela
SDL_SetRenderDrawColor( *render, 0xFF, 0xFF, 0xFF, 0xFF );
//Inicializando a biblioteca do SDL para carregar imagens .png
int imgFlags = IMG_INIT_PNG;
if( !( IMG_Init( imgFlags ) & imgFlags ) )
{
printf( "En: SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
printf( "Pt: Não foi possivel iniciar a biblioteca SDL_image! Erro: %s\n", IMG_GetError() );
sucesso = false;
}
//Inicado as bibliotecas basicas do SDL vamos inicar duas outra bibliotecas, uma de controle de som e outra de fontes
if(TTF_Init() == -1)
{
printf("En: SDL_ttf could not initialize! SDL_tff Error: %s\n", TTF_GetError() );
printf("Pt: Não foi possivel iniciar a biblioteca SDL_ttf ! SDL_tff Erro: %s\n", TTF_GetError() );
sucesso = false;
}
//Iniciando a biblioteca SDL_mixer
if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
{
printf( "En: SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() );
printf( "Pt: Não foi possivel iniciar a biblioteca SDL_mixer! Erro: %s\n", Mix_GetError() );
sucesso = false;
}
}
}
}
}
return sucesso;
}