Jump to content
  • Advertisement
Sign in to follow this  
Firestryke31

OpenGL glEnd error

This topic is 2719 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

I'm not afraid to admit I don't know OpenGL very well. However, it seemed simplest to use in my project without adding 600 dependencies and what not.

I've been poking around tutorials and the documentation, and have been able to get stuff on the screen. Then I decided to try to clean up my code.

Right now I'm at the bare minimum "draw a quad on the screen" stage. For some reason I keep getting glEnd to error (as reported by glGetError()). I'm hoping a fresh pair (or more) of eyes will help me figure out the error.


My check code:

void check()
{
GLenum error = glGetError();
if(error != GL_NO_ERROR)
{
MessageBox(NULL, L"There was a failure!", L"Assert fail!", MB_OK);
__asm int 3;
// ^^ allows me to break into the program to see error without a
// bunch of support code. I simply use the variable view in my IDE
}
}


Here's my GL state setup code:

glShadeModel(GL_SMOOTH);
glClearColor(0, 0, 0, 0);
glClearDepth(1);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


"Loading" the texture:

glGenTextures(NUM_TEXTURES, texture);
check();

// Font Texture
GLuint *fontTextureData = new GLuint[128 * 128];

// ...
// Unpack font bmp. I know this works
// ...

glBindTexture(GL_TEXTURE_2D, fontTexture);
check();

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, fontTextureData);
check();

delete[] fontTextureData;


My rendering "function:"

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glBindTexture(GL_TEXTURE_2D, fontTexture);
check();
glBegin(GL_QUADS);
check();
glVertex3f(-1.0, -1.0, -1.0);
glVertex3f(-1.0, 1.0, -1.0);
glVertex3f(1.0, 1.0, -1.0);
glVertex3f(1.0, -1.0, -1.0);
glEnd();
check();
SwapBuffers(hDC);
Sleep(0); // Sleep(0) just says "I'm done for now"

Share this post


Link to post
Share on other sites
Advertisement
It's not legal to call glGetError between a glBegin/glEnd pair. That's whats causing your error, your check() right after glBegin.

This restriction is listed in the documentation for glGetError, under "Errors"

http://www.opengl.org/sdk/docs/man/xhtml/glGetError.xml

Share this post


Link to post
Share on other sites

It's not legal to call glGetError between a glBegin/glEnd pair. That's whats causing your error, your check() right after glBegin.

This restriction is listed in the documentation for glGetError, under "Errors"

http://www.opengl.org/sdk/docs/man/xhtml/glGetError.xml


OMFG so my checking for errors was causing an error?!

tacticalfacepalm.jpg

Now to figure out why my texture isn't working (after putting the texcoord calls back in of course)...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!