#include <stdio.h>
#include <stdbool.h>
#include <SDL2/SDL.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
SDL_Window *mainWindow;
SDL_GLContext mainGLContext;
void Render() {
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(mainWindow);
}
int main(int argc, const char * argv[]) {
SDL_Init(SDL_INIT_EVERYTHING);
Uint32 flags = SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL;
int width = 640;
int height = 480;
mainWindow = SDL_CreateWindow("SDL2 OpenGL Example", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, width, height, flags);
mainGLContext = SDL_GL_CreateContext(mainWindow);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_Event e;
bool done = false;
while(!done && SDL_WaitEvent(&e)) {
switch (e.type) {
case SDL_QUIT:
done = true;
break;
default:
break;
}
Render();
SDL_Delay(20);
}
/*
SDL_GL_DeleteContext(mainGLContext);
SDL_DestroyWindow(mainWindow);
SDL_Quit();
*/
return 0;
}
网友评论