Note to myself: OpenGL gotchas

May 10th, 2009 Comments Off on Note to myself: OpenGL gotchas

Not so much “gotchas” as “got-me”s, probably. It’s been so long since I’ve done any significant OpenGL coding that I keep forgetting little things that result in a blank screen or a white texture :) Anyway, I thought I’d record them here to remind myself.

Note that I’m currently using OpenGL for 2D drawing.

  • Set glTexParameter for GL_TEXTURE_MIN_FILTER to something like GL_LINEAR before calling glTexture2D. The default value for GL_TEXTURE_MIN_FILTER is GL_NEAREST_MIPMAP_LINEAR, and if you’re not using mipmaps, the texture won’t draw!
  • I forgot that glOrtho manipulates the current matrix. Which means that if you don’t call glLoadIdentity beforehand you might not be getting the projection matrix you were hoping for!
  • This one was particularly boneheaded :P Make sure that the type parameter in glTexCoordPointer is actually the same type as the array! As in, if you pass in a pointer to an array of floats, make sure that the type parameter is set to GL_FLOAT. I blame this one on copy/pasting without paying enough attention.

Well that’s enough embarrassment for today. And I also just found this article: Avoiding 16 Common OpenGL Pitfalls, which looks useful…

EDIT: Just needed to mention another oversight that had me scratching my head for a while when things weren’t rendering as expected. Note the difference between the GL constants GL_TEXTURE and GL_TEXTURE_2D! Use the former for the parameter to glMatrixMode. Use the latter for enabling/disable texturing with glEnable/glDisable!

Comments are closed.

What's this?

You are currently reading Note to myself: OpenGL gotchas at bunnyhero dev.

meta