SDL & OpenGL interaction questions

Hey all,

Environment: Win2000, VisualC++ 6.0; GeForce3; latest service packs for OS &
compiler; latest video card driver.
User: senior level OGL programmer, new to SDL

I’ve been looking at the various examples of SDL & OpenGL and have found the
only documentation to be the function descriptions in “Chaper 6 Video” of
the general SDL documentation (from the source download.) Yes, there is the
NeHe tutorials and examples, but that is not comprehensive documentation.

I’ve not found any overview docs the describe the “nature” of the
interaction between SDL and OGL. For example, I have the following
questions:

  1. Typically, OpenGL applications don’t/can’t access the framebuffer, yet
    SDL provides routines that allow access to the framebuffer; under OGL thru
    SDL is this restriction still true?

  2. The documentation states that DirectX acceleration is used when
    available; I have DirectX 8.1 installed, but I’m coding OpenGL. The
    conventional wisdom is that one should never mix DirectX video/graphics with
    OpenGL. Under SDL, is this still true?

  3. I’ve noticed from the SDL mailing list archives some chatty comments
    about the nature/quality of NeHe’s SDL & OGL tutorials not being the best
    way to structure OpenGL applications under SDL. Asside from the coding
    style, what do the NeHe examples do that other more experienced SDL & OGL
    engineers would do different? Yeah, this is a biggie, and somewhat vague-
    I’d prefer people to reply to questions 1 & 2 rather than wax eloquent on
    this one. I’m mainly interested in any short sighted structures or
    conventions the NeHe uses which would not scale to a several hundred
    thousand line application.

Thanks,
-Blake

  1. Typically, OpenGL applications don’t/can’t access the framebuffer, yet
    SDL provides routines that allow access to the framebuffer; under OGL thru
    SDL is this restriction still true?

You’d have to use glReadPixels() to read from the framebuffer. To blit
into the framebuffer, you’d pass the SDL_OPENGLBLIT flag to
SDL_SetVideoMode(), but this is very slow, and you are better off using
OpenGL commands directly to get bits to the screen.

  1. The documentation states that DirectX acceleration is used when
    available; I have DirectX 8.1 installed, but I’m coding OpenGL. The
    conventional wisdom is that one should never mix DirectX video/graphics with
    OpenGL. Under SDL, is this still true?

The docs are referring to a 2D surface. With the exception of OPENGLBLIT,
SDL is really just meant to replace the wgl*() calls; it gives you a
portable way to create a GL context. Under Linux, this wraps the glx*()
calls. Once you’ve got a window (and hence, a context), you should just
use OpenGL as normal.

  1. I’ve noticed from the SDL mailing list archives some chatty comments
    about the nature/quality of NeHe’s SDL & OGL tutorials not being the best
    way to structure OpenGL applications under SDL. Asside from the coding
    style, what do the NeHe examples do that other more experienced SDL & OGL
    engineers would do different? Yeah, this is a biggie, and somewhat vague-
    I’d prefer people to reply to questions 1 & 2 rather than wax eloquent on
    this one. I’m mainly interested in any short sighted structures or
    conventions the NeHe uses which would not scale to a several hundred
    thousand line application.

I couldn’t say, so I’ll leave this to someone else.

–ryan.

  1. Typically, OpenGL applications don’t/can’t access the
    framebuffer, yet
    SDL provides routines that allow access to the framebuffer; under OGL thru
    SDL is this restriction still true?

SDL fakes a framebuffer with textures when the SDL_OPENGLBLIT flag is
specified during the video mode set. Generally slower than using a
regular 2d mode and mostly useless (a good GL coder can come up with a
much faster specialized system).

  1. The documentation states that DirectX acceleration is used when
    available; I have DirectX 8.1 installed, but I’m coding OpenGL. The
    conventional wisdom is that one should never mix DirectX video/graphics
    with
    OpenGL. Under SDL, is this still true?

DirectX is a big thing you know. When using OpenGL with SDL OpenGL
handles the video, and DirectInput/DirectSound is used for some stuff.
DirectDraw/Direct3D (I can’t remember which SDL actually uses) is
only used for 2D stuff.

  1. I’ve noticed from the SDL mailing list archives some chatty comments
    about the nature/quality of NeHe’s SDL & OGL tutorials not being the best
    way to structure OpenGL applications under SDL. Asside from the coding
    style, what do the NeHe examples do that other more experienced SDL & OGL
    engineers would do different? Yeah, this is a biggie, and somewhat vague-
    I’d prefer people to reply to questions 1 & 2 rather than wax eloquent on
    this one. I’m mainly interested in any short sighted structures or
    conventions the NeHe uses which would not scale to a several hundred
    thousand line application.

The main problem people have with the NeHe tutorials is that they are
written by a amateur (NeHe has admitted this himself) for ameteurs
strictly to learn OpenGL. The second problem people have is that
people think that NeHe’s quick learning approach is inferior to
learning the proper way (via SGI’s manuals). I personally believe
these are mute points, you can’t dive into that much OpenGL at once if
you are new to 3D and the spoonfeeding approach works. However you
must be willing to learn more advanced OpenGL techniques in order to
write efficient robust code. Of course if you really are a seasoned
OpenGL veteran you already know that a Vertex Array or Stored List
will toast sending primitives into the pipeline every time you build a
scene anyday :slight_smile: That’s the kind of thing that people disagree over
NeHe with. (Note: I learned from NeHe’s tutorials myself, but I will
admit that the stuff he teaches is’nt appropriate for production
quality code)

Hope that helps.

I’ve not found any overview docs the describe the “nature” of the
interaction between SDL and OGL. For example, I have the following
questions:

Yes, the SDL docs are a little rough in places.

  1. Typically, OpenGL applications don’t/can’t access the framebuffer, yet
    SDL provides routines that allow access to the framebuffer; under OGL thru
    SDL is this restriction still true?

The restriction still exists. The surface returned by SDL_SetVideoMode is
fake with SDL_OPENGL. There is a dirty, unreliable, deprecated hack in
the form of SDL_OPENGLBLIT which will let you draw right on top of your GL
context, but at a 30% performance penalty when it works at all. So yes,
you essentially have no framebuffer access.

  1. The documentation states that DirectX acceleration is used when
    available; I have DirectX 8.1 installed, but I’m coding OpenGL. The
    conventional wisdom is that one should never mix DirectX video/graphics with
    OpenGL. Under SDL, is this still true?

It is still true. SDL does not use Direct3D at all. I believe it can use
DirectSound and DirectInput with OpenGL though.

  1. I’ve noticed from the SDL mailing list archives some chatty comments
    about the nature/quality of NeHe’s SDL & OGL tutorials not being the best
    way to structure OpenGL applications under SDL. Asside from the coding
    style, what do the NeHe examples do that other more experienced SDL & OGL
    engineers would do different? Yeah, this is a biggie, and somewhat vague-
    I’d prefer people to reply to questions 1 & 2 rather than wax eloquent on
    this one. I’m mainly interested in any short sighted structures or
    conventions the NeHe uses which would not scale to a several hundred
    thousand line application.

The coding style is the biggest flaw to NeHe’s code. As a tutorial, it
teaches bad practices. That’s never good. It also takes little time to
explain what the functions in the code does other than those silly one
line comments, which is even less helpful.

I generally prefer a subsystem-based approach, personally. It works very
well for games and makes SDL_main about five to six lines long, in total.
It looks scarily like the kind of code I learned to write in school (and
subsiquently learned was basically never really used in solving real world
problems - except for frame-based games I suppose, eh?)On Sat, Apr 06, 2002 at 09:41:23AM -0800, Blake Senftner wrote:


Joseph Carter My opinions are always right

  • Endy needs to consult coffee :stuck_out_tongue:
    coffee the bot person, not coffee the beverage :slight_smile:
    consulting the beverage may help too =>

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020406/6106525c/attachment.pgp