#include "SDL.h" #include #include #include #include using std::stringstream; using std::string; GLsizei windowWidth = 1600; GLsizei windowHeight = 900; bool fullScreen = false; bool useAA = true; const Uint8 *keys = NULL; int main(int argc, char **argv) { if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Unable to initialize SDL %s", SDL_GetError()); exit(1); } if (useAA ) { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 8); } Uint32 flags; if(fullScreen) { flags = SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN; } else flags = SDL_WINDOW_OPENGL; SDL_Window* the_window; the_window = SDL_CreateWindow("testing", 90, 60, windowWidth, windowHeight, flags); if ( !the_window ) { fprintf(stderr, "Unable to create OpenGL Scene: %s", SDL_GetError()); exit(2); } SDL_GLContext glcontext = SDL_GL_CreateContext(the_window); glewExperimental = GL_TRUE; if (glewInit() != GLEW_OK) { MessageBox(0, "Failed to initialize GLEW", "Error", MB_OK); return -1; } SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); int maj; int min; SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,&maj); SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,&min); stringstream strstrm (stringstream::in | stringstream::out); strstrm << "gl major version: " << maj << "\ngl minor version: " << min; string the_msg = strstrm.str(); MessageBox(0, the_msg.c_str(), "current opengl version", MB_OK); glMatrixMode(GL_PROJECTION|GL_MODELVIEW); glLoadIdentity(); glOrtho(-320,320,240,-240,0,1); float x = 0.0, y = 30.0; int done = 0; SDL_Event event; while ( !done ) { while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_QUIT ) done = -1; keys = SDL_GetKeyboardState(NULL); } float frameTime; float curTime = SDL_GetTicks(); static float lastTime = 0; frameTime = curTime - lastTime; glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT); glRotatef(0.09*(frameTime),0.0,0.0,1.0); glBegin(GL_TRIANGLES); glColor3f(1.0,0.0,0.0); glVertex2f(x, y+90.0); glColor3f(0.0,1.0,0.0); glVertex2f(x+90.0, y-90.0); glColor3f(0.0,0.0,1.0); glVertex2f(x-90.0, y-90.0); glEnd(); SDL_GL_SwapWindow(the_window); if ( keys[SDL_SCANCODE_ESCAPE] ) { done = 1; } lastTime = curTime; } SDL_Quit(); return 1; }