Sign in to follow this  
  • entries
    8
  • comments
    6
  • views
    7461

Finally some light at the end of the tunnel

Sign in to follow this  

276 views

First off let me say how much of an idiot I am. Next, lets restate the obvious... *IDIOT*.

Past week or so I have been having problems adding simple un-filled primitives to my SDL/OpenGL library. The colors were getting skewed and since I am not at all familiar with 3d graphics concepts I did what anyone would do before posting my problems in the forums. I read. I read some more. I googled, I yahoo'd, I even asked jeeves. Unfortunately none of these things got it through my thick skull what was going wrong.

Here is the lowdown:
Drawing primitives by themselves works fine as long as I didn't load any textures. However, Load a texture and for some reason the primitives colors get all whacked out. Thinking it was the blending or alpha test I spent many days reading and pulling out hair from many trials and even more errors. My texture loading code worked fine. The blending/alpha test worked fine. But I could not color the primitives.

Here was the solution:
Being the GL newbie I am, I didn't realize what enabling or disabling all of these states do. I had blending, alpha testing, point, line smoothing, and depth testing enabled and disabled at button presses to see if these were the problem. I learned a lot but still no dice. Here is the kicker. When drawing textured geometry, GLTEXTURE_2D is required to be enabled. However, when not drawing textured geometry, it totally screws up everything else if it is still enabled. So, by disabling GL_TEXTURE_2D before drawing primitives, this solved my problem.

Conclusion:
*IDIOT*

Anyway, not sure if this is the proper solution to my problem but it worked for me.

Currently in my GL2D library I have C style functions to:
-Load bitmaps to textures
-Set color keys on textures (fake it baby)
-SDL style blits (destination surface is ignored and sent to screen)
-Alpha blending/transparency
-Rotation
-Scaling
-Primitives: lines, rectangles, polygons, circles (filled or empty)

Some other conclusions:
There will never be a perfect 2D wrapper for OpenGL. Mainly because in order to wrap the functionality of OpenGL in 2D and hide the underlying 3D API from the user, you must trade off efficiency for ignorance. For example, batching textured quads by texture to cut down the number of glBindTexture, glBegin and glEnd calls will significantly improve your applications performance. However, in order to hide this pain in the arse from the end user, one must use glBindTexture, glBegin and glEnd calls inside the wrapped 2d blit function so the end user does not need to worry about doing these things at the cost of inefficiency. While the performance increase from using a 3D API as opposed to a 2D one is worth it even with these inefficiencies, one will eventually end up writing their own game specific rendering code.

Onward and sally forth!

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now