# OpenGL/glut and SDL

**URL:** <https://discourse.libsdl.org/t/opengl-glut-and-sdl/1561>\
**Category:** SDL Development\
**Created:** [January 18, 2000, 3:48am UTC](https://discourse.libsdl.org/t/opengl-glut-and-sdl/1561 "2000-01-18T03:48:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lucas\_Ackerman](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/cdc98d/32.png) [@Lucas\_Ackerman](https://discourse.libsdl.org/u/Lucas_Ackerman)\
**Post date:** [January 18, 2000, 3:48am UTC](https://discourse.libsdl.org/t/opengl-glut-and-sdl/1561/1 "2000-01-18T03:48:04Z")

</div>

Hello. I am new to SDL and am wondering if it is possible to use SDL  
for keyboard & mouse i/o, audio, events, threads, timing, etc, but use  
OpenGL via glut for all video/graphics commands. Will SDL run happily  
with something else in control of video? I see on this newsgroup that  
some people are working on an integrated OpenGL interface for SDL, but I  
don’t think I need that much if I can just use glut seperately and let  
SDL do its thing independantly. Also, could I just use SDL video  
commands internally, without ever setting a video mode, for bitmap  
manipulation and such? Would the SDL\_WM commands for window management  
still be available? I guess I just need to know to what extent SDL  
requires control of this stuff and if I’ll be able to work around it.  
Thanks,

-Lucas

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [January 18, 2000, 5:26am UTC](https://discourse.libsdl.org/t/opengl-glut-and-sdl/1561/2 "2000-01-18T05:26:00Z")

</div>

> Hello. I am new to SDL and am wondering if it is possible to use SDL  
> for keyboard & mouse i/o, audio, events, threads, timing, etc, but use  
> OpenGL via glut for all video/graphics commands. Will SDL run happily  
> with something else in control of video? I see on this newsgroup that  
> some people are working on an integrated OpenGL interface for SDL, but I  
> don’t think I need that much if I can just use glut seperately and let  
> SDL do its thing independantly. Also, could I just use SDL video  
> commands internally, without ever setting a video mode, for bitmap  
> manipulation and such? Would the SDL\_WM commands for window management  
> still be available? I guess I just need to know to what extent SDL  
> requires control of this stuff and if I’ll be able to work around it.

Actually, using OpenGL with SDL is very easy. I’m attaching the first  
in a set of OpenGL tutorials I will make available on the SDL website  
when the OpenGL support is implemented on all platforms.

See ya!  
-Sam Lantinga (slouken at [devolution.com](http://devolution.com))

Lead Programmer, Loki Entertainment Software–  
“Any sufficiently advanced bug is indistinguishable from a feature”  
– Rich Kulawiec  
-------------- next part --------------  
//  
// This code was created by Jeff Molofee '99  
// (ported to SDL by Sam Lantinga '2000)  
//  
// If you’ve found this code useful, please let me know.  
//  
// Visit me at [www.demonews.com/hosted/nehe](http://www.demonews.com/hosted/nehe)  
//  
#include \<GL/gl.h\> // Header File For The OpenGL32 Library  
#include \<GL/glu.h\> // Header File For The GLu32 Library  
#include “SDL.h”

/\* A general OpenGL initialization function. Sets all of the initial parameters. \*/  
void InitGL(int Width, int Height) // We call this right after our OpenGL window is created.  
{  
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black  
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer  
glDepthFunc(GL\_LESS); // The Type Of Depth Test To Do  
glEnable(GL\_DEPTH\_TEST); // Enables Depth Testing  
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);  
}

/\* The main drawing function. \*/  
void DrawGLScene()  
{  
glClear(GL\_COLOR\_BUFFER\_BIT | GL\_DEPTH\_BUFFER\_BIT); // Clear The Screen And The Depth Buffer  
glLoadIdentity(); // Reset The View

glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0

// draw a triangle  
glBegin(GL\_POLYGON); // start drawing a polygon  
glVertex3f( 0.0f, 1.0f, 0.0f); // Top  
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right  
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left   
glEnd(); // we’re done with the polygon

glTranslatef(3.0f,0.0f,0.0f); // Move Right 3 Units

// draw a square (quadrilateral)  
glBegin(GL\_QUADS); // start drawing a polygon (4 sided)  
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left  
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right  
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right  
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left   
glEnd(); // done with the polygon

// swap buffers to display, since we’re double buffered.  
SDL\_GL\_SwapBuffers();  
}

int main(int argc, char \*\*argv)  
{  
int done;

/\* Initialize SDL for video output \*/  
if ( SDL\_Init(SDL\_INIT\_VIDEO) \< 0 ) {  
fprintf(stderr, “Unable to initialize SDL: %s\n”, SDL\_GetError());  
exit(1);  
}

/\* Create a 640x480 OpenGL screen \*/  
if ( SDL\_SetVideoMode(640, 480, 0, SDL\_OPENGL) == NULL ) {  
fprintf(stderr, “Unable to create OpenGL screen: %s\n”, SDL\_GetError());  
SDL\_Quit();  
exit(2);  
}

/\* Set the title bar in environments that support it \*/  
SDL\_WM\_SetCaption(“Jeff Molofee’s GL Code Tutorial … NeHe '99”, NULL);

/\* Loop, drawing and checking events \*/  
InitGL(640, 480);  
done = 0;  
while ( ! done ) {  
DrawGLScene();

```
/* This could go in a separate function */
{ SDL_Event event;
  while ( SDL_PollEvent(&event) ) {
    if ( event.type == SDL_QUIT ) {
      done = 1;
    }
    if ( event.type == SDL_KEYDOWN ) {
      if ( event.key.keysym.sym == SDLK_ESCAPE ) {
        done = 1;
      }
    }
  }
}

```

}  
SDL\_Quit();  
return 1;  
}

---

<div class="post-metadata">

**Author:** ![Nicholas\_Vining](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/n/f04885/32.png) [@Nicholas\_Vining](https://discourse.libsdl.org/u/Nicholas_Vining)\
**Post date:** [January 18, 2000, 5:53am UTC](https://discourse.libsdl.org/t/opengl-glut-and-sdl/1561/3 "2000-01-18T05:53:12Z")

</div>

> Newsgroups: loki.open-source.sdl
> 
> > Hello. I am new to SDL and am wondering if it is possible to use SDL  
> > for keyboard & mouse i/o, audio, events, threads, timing, etc, but use  
> > OpenGL via glut for all video/graphics commands. Will SDL run happily  
> > with something else in control of video? I see on this newsgroup that  
> > some people are working on an integrated OpenGL interface for SDL, but I  
> > don’t think I need that much if I can just use glut seperately and let  
> > SDL do its thing independantly. Also, could I just use SDL video  
> > commands internally, without ever setting a video mode, for bitmap  
> > manipulation and such? Would the SDL\_WM commands for window management  
> > still be available? I guess I just need to know to what extent SDL  
> > requires control of this stuff and if I’ll be able to work around it.  
> > Thanks,
> 
> The reason that we all got together and added an integrated OpenGL interface  
> for SDL (the GLX version of which is done and stable, and the other versions  
> of which I will keep working on once I get a new video card =) were written  
> to replace GLUT as a front end for gaming applications, on the ground that  
> it was unnecessarily nasty, slow, and poorly implemented. Or at least I  
> thought it was, and evidently so did some Loki software mugga-muggs, because  
> between about five of us, it was written.
> 
> GLUT will in all likelihood NOT work. AFAIK it attempts to do its own  
> context and input management, and SDL is so bound up in the video code that  
> disabling it isn’t much of a possibility. You might be able to do it at  
> compile time, but it would be ugly. You CAN still get audio support running.  
> I think there was a demo around here somewhere that did some of this sort of  
> thing, and I’m sure you could come up with some sort of external GLX  
> interface with massively nasty hacking, but GLUT… I don’t think that would  
> be good.
> 
> Just use SDL\_GL instead, it’s cooler.
> 
> > -Lucas
> 
> Nicholas
> 
> > ----- Original Message -----  
> > From: ackerman@wpi.edu (Lucas Ackerman)  
> > To: sdl at [lokigames.com](http://lokigames.com)   
> > Date: Monday, January 17, 2000 8:05 PM  
> > Subject: [SDL] OpenGL/glut and SDL

---

<div class="post-metadata">

**Author:** ![Lucas\_Ackerman](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/cdc98d/32.png) [@Lucas\_Ackerman](https://discourse.libsdl.org/u/Lucas_Ackerman)\
**Post date:** [January 18, 2000, 10:42pm UTC](https://discourse.libsdl.org/t/opengl-glut-and-sdl/1561/4 "2000-01-18T22:42:21Z")

</div>

ok, thanks 🙂 from the looks of things i think i may as well just go ahead  
and use SDL\_OPENGL. can anyone give me a rough timeframe on the win32  
(win9x) SDL\_OPENGL implimentation? soon/weeks/months? if its going to be  
some time, would it be worthwhile to tackle it myself? i use both win95 and  
Linux, but i think i need win9x support on this project from the start (cuz  
im working with another person). my gut reaction is “rip the equivelant  
glut code, stick it in SDL,” but i’m not very familiar with the source of  
either.

-Lucas

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [January 18, 2000, 11:04pm UTC](https://discourse.libsdl.org/t/opengl-glut-and-sdl/1561/5 "2000-01-18T23:04:01Z")

</div>

> ok, thanks 🙂 from the looks of things i think i may as well just go ahead  
> and use SDL\_OPENGL. can anyone give me a rough timeframe on the win32  
> (win9x) SDL\_OPENGL implimentation? soon/weeks/months? if its going to be  
> some time, would it be worthwhile to tackle it myself? i use both win95 and  
> Linux, but i think i need win9x support on this project from the start (cuz  
> im working with another person). my gut reaction is “rip the equivelant  
> glut code, stick it in SDL,” but i’m not very familiar with the source of  
> either.

Soon/weeks. The actual implementation is very simple - only a few dozen  
lines of code. It will be implemented as soon as anyone has time to do it.

```
-Sam Lantinga (slouken at devolution.com)

```

Lead Programmer, Loki Entertainment Software–  
“Any sufficiently advanced bug is indistinguishable from a feature”  
– Rich Kulawiec

---

<div class="post-metadata">

**Author:** ![Nicholas\_Vining](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/n/f04885/32.png) [@Nicholas\_Vining](https://discourse.libsdl.org/u/Nicholas_Vining)\
**Post date:** [January 19, 2000, 1:00am UTC](https://discourse.libsdl.org/t/opengl-glut-and-sdl/1561/6 "2000-01-19T01:00:14Z")

</div>

> Newsgroups: loki.open-source.sdl
> 
> > ok, thanks 🙂 from the looks of things i think i may as well just go ahead  
> > and use SDL\_OPENGL. can anyone give me a rough timeframe on the win32  
> > (win9x) SDL\_OPENGL implimentation? soon/weeks/months? if its going to be  
> > some time, would it be worthwhile to tackle it myself? i use both win95  
> > and  
> > Linux, but i think i need win9x support on this project from the start (cuz  
> > im working with another person). my gut reaction is “rip the equivelant  
> > glut code, stick it in SDL,” but i’m not very familiar with the source of  
> > either.
> 
> This is one of the gazillion things on my todo list, except it’s not one  
> that I’m actually looking forward to doing. Maybe tonight, if I have some  
> spare time (my life is so f\*\*\*in’ hectic right now)
> 
> > -Lucas
> 
> Nicholas
> 
> > ----- Original Message -----  
> > From: ackerman@wpi.edu (Lucas Ackerman)  
> > To: sdl at [lokigames.com](http://lokigames.com)   
> > Date: Tuesday, January 18, 2000 3:00 PM  
> > Subject: [SDL] Re: OpenGL/glut and SDL
