Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Webbster

OpenGL OpenGL with SDL

This topic is 5493 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can I use OpenGL in conjunction with SDL to get the best of both worlds, as well as make the final product cross platform? My idea is to create my environments and graphics such as particle systems and models using OpenGL and then using SDL to create my app''s window and allow for Music, Sound and Input. Is this possible or am I missing something. Thanks Ad

Share this post


Link to post
Share on other sites
Advertisement
Yes. Parts of SDL are specifically designed to make cross-platform OpenGL initialization very easy. Read the SDL docs.

Share this post


Link to post
Share on other sites
On the tutorials section of the SDL website there''s a link to download the sources for the NeHe tutorials in SDL

Share this post


Link to post
Share on other sites
The problem with SDL and OpenGL is that on Windows, SDL uses the old-school context set-up functions, so you can''t request modern features like pbuffers. Well, last I looked, anyway; I haven''t seen anything about updating it to use WGL_ARB_pixel_format so I think it''s still a limitation.

Share this post


Link to post
Share on other sites
When it comes to using OpenGL in an SDL window, are their any alterations to the OGL code or is it a point of when I''ve initialized an SDL window, it just becomes a matter of creating the rest with OpenGL as normal. I haven''t really had time to study the SDL Docs much so any further help would be appreciated.

Thanks, Ad.

PS Are there any known performance hit''s concerning the use of SDL for sound and input along side OpenGL for Graphics?

Share this post


Link to post
Share on other sites
Find time to read the docs

Basically all it requires is setting of a few flags. The above posters have pointed out a potential problem with relying on SDL, but for reasonably simple applications you shouldn''t have a problem.

As soon as OpenGL is initialized, it is no different to using it with your own init code, so there is no performance hit to using other libs along side than would result from doing it yourself.

Share this post


Link to post
Share on other sites
This should setup SDL for you

void InitSDL(void)
{
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
ofstream fout("error.log");
fout << "Unable to Init SDL video!!\n";
fout.close();
exit(0);
}

if(SDL_SetVideoMode(1024, 768, 32, SDL_FULLSCREEN | SDL_OPENGL) == NULL)
{
ofstream fout("error.log");
fout << "Unable to Init SDL videomode!!\n";
fout.close();
SDL_Quit();
exit(0);
}
}//end of void InitSDL(void)


//**************************

void InitOpenGL(int width, int height)
{
glViewport(0, 0, width, height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black

glClearDepth(1.0f); // Enables Clearing Of The Depth Buffer

glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do

glEnable(GL_DEPTH_TEST); // Enables Depth Testing

glEnable(GL_TEXTURE_2D);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtering

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtering

glGenTextures(3, texture);

glBindTexture(GL_TEXTURE_2D, texture[0]);
load_texture("bitmap.png");
glBindTexture(GL_TEXTURE_2D, texture[1]);
load_texture("bitmap1.png");
glBindTexture(GL_TEXTURE_2D, texture[2]);
load_texture("bitmap2.png");

glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading

glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // Reset The Projection Matrix

gluPerspective(45.0f, (GLfloat) width/(GLfloat) height, 0.1f, 100.0f); // Calculate The Aspect Ratio Of The Window

glMatrixMode(GL_MODELVIEW);
}//end of void InitOpenGL(int height, int width)


Its bee awhile since I have used SDL so tread carefully.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!