SDL+OpenGL not drawn
I'm using SDL+OpenGL to draw graphics. It works on a lot of PC's, but appearantly for some people it doesn't work.
Here's the game and the code: http://members.gamedev.net/lode/games/towerwars/.
On some PC's, the screen isn't drawn, the window + titlebar is visible, but the contents aren't drawn, it's not black, but just contains whatever used to be behind it on the MS Windows desktop.
I'm not sure if this is the cause of the problem, but this is the parameters I use to create the window with SDL:
scr = SDL_SetVideoMode(width,height,colorDepth,SDL_HWSURFACE|SDL_HWPALETTE|SDL_OPENGL);
But the returned scr isn't 0, otherwise the application would have crashed for those people instead of showing a window with nothing drawn on it, at least I THINK so, maybe OpenGL doesn't require the returned scr to be valid?
The rest of the code can be found in the link above. The screen is made in "lpi_screen.cpp"
What could be the cause of this problem? It fails on a laptop with a shared memory videocard, and on someone's fairly modern PC with normal hardware accelaration on it.
Since on my own PC's it draws everything, I find it very hard to debug this problem.
A few things right off the top of my head, you do not need to enable hardware acceleration and the hardware palette with those flags. The SDL_OPENGL flag is enough, it will use whatever the systems implementation of OpenGL uses. Another thing, look into SDL_GL_SetAttribute you should call those before SDL_SetVideoMode
Quote:Original post by ImperfectFreak
A few things right off the top of my head, you do not need to enable hardware acceleration and the hardware palette with those flags. The SDL_OPENGL flag is enough, it will use whatever the systems implementation of OpenGL uses. Another thing, look into SDL_GL_SetAttribute you should call those before SDL_SetVideoMode
Which of those attributes should be set? Will setting these 4 be enough?
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
Or should also the one about double buffering be set?
Also, if I'd set the color bits to 5 instead of 8, will it still use 8 if the computer can handle it? If I'd set depth to 8, will it still use 16 if the computer can do it? If so, if it always takes the best available, what do these function calls mean?
They are the settings for your framebuffer. The sizes are saying how many bits are allocated for red, green, blue, and usually alpha. I usually set red, green, blue, and alpha to 8 bits each adding up to 32 bits which is usually the fastest setting on a 32 bit system. I usually set the depth size to 16, but if your game is 2D I doubt you even need 16 bits for depth, if you even have depth testing enabled. Also, there are settings for the accumulation buffer and the stencil buffer, which I don't think you are using. And yes you should set doublebuffer to 1.
To make the screen I now do this:
Then this:
Which then also calls this:
Every frame I do this:
If content of other function needed: the code is under the link given in the original post.
So I added the SDL_GL_SetAttribute's!
And it still doesn't work on this persons PC, it still gives a screen with nothing drawn on it, not even black.
What else could be wrong!?
void screen(int width, int height, bool fullscreen, const char* text){ int colorDepth = 32; w = width; h = height; if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { printf("Unable to init SDL: %s\n", SDL_GetError()); SDL_Quit(); exit(1); } atexit(SDL_Quit); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); if(fullscreen) { scr = SDL_SetVideoMode(width,height,colorDepth,SDL_FULLSCREEN|SDL_OPENGL); lock(); fullscreenMode = 1; } else { scr = SDL_SetVideoMode(width,height,colorDepth,SDL_OPENGL); fullscreenMode = 0; } if(scr == 0) { printf("Unable to set video: %s\n", SDL_GetError()); SDL_Quit(); exit(1); } SDL_WM_SetCaption(text, NULL); initGL(); SDL_EnableUNICODE(1); //for the text input things cls(); //initialize the scissor area (the values at position std::vector.size() - 1 in the std::vectors must ALWAYS be set to the values below and may never be changed!) clipLeft.clear(); clipLeft.push_back(0); clipTop.clear(); clipTop.push_back(0); clipRight.clear(); clipRight.push_back(w); clipBottom.clear(); clipBottom.push_back(h); //plane.create(RGB_Black, w, h); initBuiltInFontTextures(); gui::initBuiltInGuiTextures();}
Then this:
void initGL(){ set2DScreen(); //glShadeModel(GL_FLAT); //shading, don't do the GL_FLAT thing or gradient rectangles don't work anymore //glCullFace(GL_BACK); //culling //glFrontFace(GL_CCW); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glDisable(GL_ALPHA_TEST); glEnable(GL_SCISSOR_TEST); //scissoring is used to, for example, not draw parts of textures that are scrolled away, and is always enabled (but by default the scissor area is as big as the screen) }
Which then also calls this:
void set2DScreen(){ if(screenMode == 0) return; screenMode = 0; //the official code for "Setting Your Raster Position to a Pixel Location" (i.e. set up an oldskool 2D screen) glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, w, h, 0, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); enableTwoSided(); //important, without this, 2D stuff might not be drawn if only one side is enabled disableZBuffer(); disableSmoothing();}
Every frame I do this:
void redraw(){ SDL_GL_SwapBuffers();}
If content of other function needed: the code is under the link given in the original post.
So I added the SDL_GL_SetAttribute's!
And it still doesn't work on this persons PC, it still gives a screen with nothing drawn on it, not even black.
What else could be wrong!?
what does that lock function do? If it calls SDL_LockSurface on your video surface that is probably a bad thing.
Quote:Original post by ImperfectFreak
what does that lock function do? If it calls SDL_LockSurface on your video surface that is probably a bad thing.
The lock() function is only used in case of fullscreen. However my problem happens in windowed mode, where lock() isn't called.
To be honest, I haven't used or tested the fullscreen mode for years, back when I made it it didn't work without locking the surface.
Anyway fullscreen can be ignored for now, the problem is in windowed mode.
Is it possible at all with SDL to make an OpenGL application that will be correctly drawn in all Windows PC's that have the correct drivers? Has anyone ever made a game using SDL+OpenGL and noticed it doesn't work on some PC's?
Have you read This article?
Im currently learning SDL with GL so if you like i can try running a debugger on my laptop (it has shared mem and the app fails).
I have some advice, i notice you dont perform any error checks and fallbacks for the video setup etc, maybe some extra work testing various modes and debug strings to log file will help narrow down the problem (i.e. get people to submit their logs).
Im currently learning SDL with GL so if you like i can try running a debugger on my laptop (it has shared mem and the app fails).
I have some advice, i notice you dont perform any error checks and fallbacks for the video setup etc, maybe some extra work testing various modes and debug strings to log file will help narrow down the problem (i.e. get people to submit their logs).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement