c - SDL+OpenGL app: blank screen -


I tried to create a small app in the last three days using SDL + OpenGL. The app is running fine - except that it never outputs any graphics; Just a black screen.

I've switched it to at least one file, and I hope someone can give me some guidance. I'm running away from ideas.

I use Windows Vista, MinGW & amp; MSYS Thanks in advance for any advice!

  #include & lt; SDL / SDL.h & gt; # Include & lt; SDL_opengl.h & gt; Size_t sx = 600, sy = 600, bpp = 32; Zero render (zero) {glEnable (GL_DEPTH_TEST); // Enable Depth Testing glClearColor (0.0f, 0.0f, 0.0f, 0.0f); // Clear the Black Glitter (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color / depth buffer glLoadIdentity (); // Reset ModelView Matrix glColor3b (255, 0, 0); // Red Gillin Wide (3.0); // line width = 3 glracti (10, 10, SX-10, SI-10); // Rectangle size glFlush (); SDL_GL_SwapBuffers (); } Int input (zero) {SDL_Event event; While (SDL_PollEvent (and event)) if (event.type == SDL_QUIT || (event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_ESCAPE)) Return 0; Return 1; } Int main (int argc, char * argv []) {SDL_Surface * Surf; If (SDL_Init (SDL_INIT_EVERYTHING)! = 0) 0 back; If (Surf = SDL_SetVideoMode (SX, SIP, BPP, SDL_HWASEACE | SDL_DOUBLEBUF)) returns 0; GlViewport (0, 0, sx, sy); // Reset the viewport to new dimensions glMatrixMode (GL_PROJECTION); // current launch matrix current glow load id (;); // Reset projection matrix glotho (0, SX, SI, 0, -1.0, 1.0); // Ortho Visual Glamorics Moded (GLIMDLUF) to create; // Set ModelView Matrix Gloled Identity (); // ModelViewor Matrix for Reset (;;) (if break! (Input!); Render (); SDL_Delay (10);} SDL_FreeSurface (SDK); SDL_Quit (); Exit (0);} < / Code> 

UPDATE: I have a version that works, but it changes the intent change for perspective. I am not sure why this works and not the second, but the future For reference, this is a version that works:

  #include & lt; SDL / SDL.h & gt; # Include & lt; SDL_opengl.h & Gt; Size_t sx = 600, sy = 600, bpp = 32; zero render (zero) {glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity (); // set the location in front of the camera glTranslated (0, 0, -10); GlBegin (GL_QUADS); // Take a square glColor3d (1, 0, 0); Glitax 3D (-2, 2, 0); Glyvertex 3D (2, 2, 0); Glitax 3D (2, -2) , 0); Glitax 3D (-2, -2, 0); glEnd (); glFlush (); SDL_GL_SwapBuffers ();} Int input (zero) {SDL_Event event; while (SDL_PollEvent (and event)) if (event .type == SDL_QUIT || (Event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_ESCAPE)) Return 0; Return 1; } Int main (int argc, char * argv []) {SDL_Surface * Surf; If (SDL_Init (SDL_INIT_EVERYTHING)! = 0) 0 back; If (Surf = SDL_SetVideoMode (SX, SI, BPP, SDL_OPANGL)) returned 0); GlViewport (0, 0, sx, sy); GlMatrixMode (GL_PROJECTION); GlLoadIdentity (); Glue Perspective (45.0, (Float) SX / (Float) C, 1.0, 100.0); GlMatrixMode (GL_MODELVIEW); Glacolar roller (0, 0, 0, 1); GlClearDepth (1.0); GlEnable (GL_DEPTH_TEST); For (;;) {if (! Input ()) break; to present(); SDL_Delay (10); } SDL_FreeSurface (Surf); SDL_Quit (); Return 0; Change your  glColor3b () in the first code block  

call GlColor3ub () . Or pass in 127 instead of 255.


Comments