OpenGL and SDL integration |
Alex Barry
Guest
|
I'm attempting to integrate OpenGL into SDL by including <GL\gl.h> instead
of doing all this weird dynamic stuff (because I have no idea how to do it) Anyway, whenever I startup the videa with the SDL_OPENGL flag, the video doesn't work and it aborts (without going through my error checking) Any thoughts? Alex~ Here's some code, too: class ScreenData { public: void set( int xres, int yres, int bbp, Uint32 flags ); /* Set video (will clear previous page if set) */ void setgl( int xmin, int ymin, int xmax, int ymax ); /* set opengl window */ SDL_Surface *page; /* Screen Surface */ }; void ScreenData::set( int xres, int yres, int bbp, Uint32 flags ) /* sets the video mode appropriately */ { if( page ) { SDL_FreeSurface( page ); /* If there is an existant page, clear it */ } page = SDL_SetVideoMode (xres, yres, bbp, flags ); /* Reset the page to the current */ if( page == NULL ) { char* msg; sprintf( msg, "Couldn't set %dx%dx%d video mode: %s\n", xres, yres, bbp, SDL_GetError ( ) ); MessageBox( 0, msg, "Error", MB_ICONHAND ); free( msg ); exit( 2 ); } } void ScreenData::setgl( int xmin, int ymin, int xmax, int ymax ) /* Setup OpenGL video */ { glViewport(xmin, ymin, xmax, ymax); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); glMatrixMode(GL_PROJECTION); glMatrixMode(GL_MODELVIEW); } /* #################################### */ int main (int argc, char *argv[]) { char *msg; int done; /* Initialize SDL */ if (SDL_Init (SDL_INIT_VIDEO) < 0) { sprintf (msg, "Couldn't initialize SDL: %s", SDL_GetError ()); progshutdown( screen.page, true, "SDL Initialization Error", msg, 27 ); } atexit (SDL_Quit); if(TTF_Init()==-1) { sprintf (msg, "Couldn't initialize SDL_ttf: %s\nError Code: 0x02", TTF_GetError() ); MessageBox (0, msg, "Error", MB_ICONHAND); free (msg); exit(2); } atexit( TTF_Quit ); screen.set( 800, 600, 16, SDL_OPENGL | SDL_HWSURFACE | SDL_NOFRAME ); screen.setgl( 0, 0, 800, 600 ); // this sets up the opengl window view port and such... SDL_WM_SetCaption ("Atosoft++ (c) 2006", NULL); // there's more, but it's irrelevant } -- Smith: "...Why, Mr Anderson, Why - Do - You - Persist?" Neo: "Because I choose to." -Matrix Revolutions -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060106/8358f31e/attachment.htm |
|||||||||||
|
OpenGL and SDL integration |
OpenGL and SDL integration |
Ryan C. Gordon
Guest
|
Don't call FreeSurface on the return value from SDL_SetVideoMode().
Your sprintf() is writing to an uninitialized pointer, and freeing it, too. --ryan. |
|||||||||||||||
|
OpenGL and SDL integration |
Damien A
Guest
|
OK, here goes:
Both statements in your Initialise SDL block are not written correctly. 1) The character pointer msg is not initialised before it is used. I'll assume that you forgot to put that in the snippet . Just make sure that the size of the buffer that it points to is large enough to hold the final error message. 2) Although I don't know what progshutdown does, it seems as though it writes a message to the 'SDL_Surface *page'. This pointer (assuming you declared 'screen' as 'ScreenData screen', and forgot to put it in the code snippet), can't hold a valid SDL Surface if SDL's Video subsystem is _not_ initialised, so you should redirect your error to a file, or message box. Besides those, here are somethings you might want to consider: As you are using the SDL_OPENGL flag, SDL_HWSURFACE is unnecessary. Also if you are using OpenGL for rendering, you won't need to save the surface returned by SDL_SetVideoMode. Just set up your projection and model view matrices to suit your application. You simply select a matrix, and then move on to another, but don't set them to anything meaningful. Reread whatever tutorials you are using, and take a look at the opengl redbook (you can google for that) for more information on using opengl. Here is a useful opengl FAQ: http://www.gamedev.net/community/forums/showfaq.asp?forum_id=25 Alex Barry wrote:
|
|||||||||||||
|