PDA

View Full Version : glGetError() always returns GL_INVALID_OPERATION



benadam777
06-27-2009, 04:11 PM
Hello,

I'm trying to code a button that uses OpenGL and Qt for rendering. I am running into a problem where immediately after constructing the main window, I make a looped call to glGetError() to both check and clear any errors. I am doing this in hopes of troubleshooting why textures aren't being mapped to the button object. Either way, the texture isn't mapping and glGetError() always returns GL_INVALID_OPERATION any time I call it. Here is the source code:

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
while(glGetError() != GL_NO_ERROR)
glGetError();//<-always returns GL_INVALID_OPERATION
GLError glError = GLError();
QString str = glError.checkGLErrors();
.....

void AiderButton::setTexture(const char *pTextureFileName)
{
texture = new QImage(QGLWidget::convertToGLFormat(QImage(pTextur eFileName)));
glEnable(GL_TEXTURE_2D);
glGenTextures(1,&amp;textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, this->texture->width(), this->texture->height(),
0, GL_RGB, GL_UNSIGNED_BYTE, this->texture->bits());
GLError glError = GLError();
QString str = glError.checkGLErrors();
QString str2 = str;
}

void AiderButton::render()
{
glPushAttrib(GL_POLYGON_BIT);
glPushAttrib(GL_CURRENT_BIT);

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
QPointF ul = this->getCornerCoords(AiderButton::UPPER_LEFT);
QPointF ur = this->getCornerCoords(AiderButton::UPPER_RIGHT);
QPointF lr = this->getCornerCoords(AiderButton::LOWER_RIGHT);
QPointF ll = this->getCornerCoords(AiderButton::LOWER_LEFT);

if(this->texture != NULL)
{
glBindTexture(GL_TEXTURE_2D, textureID);
}
glBegin(GL_QUADS);
glNormal3f(0.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f);glVertex3f(ll.x(), ll.y(), 0.0f);//lower left, tex-coord(0,1)
glTexCoord2f(1.0f, 0.0f);glVertex3f(lr.x(), lr.y(), 0.0f);//lower right, tex-coord(1,1)
glTexCoord2f(1.0f, 1.0f);glVertex3f(ur.x(), ur.y(), 0.0f);//upper right, tex-coord(1,0)
glTexCoord2f(0.0f, 1.0f);glVertex3f(ul.x(),ul.y(), 0.0f); //upper left, tex-coord(0,0)
glEnd();

glPopAttrib();//GL_CURRENT_BIT
glPopAttrib();//GL_POLYGON_BIT

GLError glError = GLError();
QString str = glError.checkGLErrors();
}

Any suggestions are greatly appreciated.

Thank You

mfort
06-28-2009, 01:57 AM
OpenGL context not created or not made current. Each thread that wants to use OpenGL must have OpenGL context.

For Qt, read QGLWidget docs.