Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm having problems drawing a simple sprite. When I draw:

void CSprite2D::render()
    {
        CHECKGL(glLoadIdentity());
        CHECKGL(glEnable(GL_TEXTURE_2D));
        CHECKGL(glEnable(GL_BLEND));

        CHECKGL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));

        m_texture->bind();

        //CHECKGL(glPushMatrix());

        CHECKGL(glBegin(GL_TRIANGLE_STRIP));
            CHECKGL(glNormal3i(0,0,1));
            CHECKGL(glTexCoord2f(m_textureAreaStart.s,m_textureAreaStart.t)); // 0,0 by default
            CHECKGL(glVertex3i(m_position.x,m_position.y,0));

            CHECKGL(glNormal3i(0,0,1));
            CHECKGL(glTexCoord2f(m_textureAreaEnd.s,m_textureAreaStart.t)); // 1,0 by default
            CHECKGL(glVertex3i( m_position.x + m_dimensions.x, m_position.y, 0));   

            CHECKGL(glNormal3i(0,0,1));
            CHECKGL(glTexCoord2f(m_textureAreaEnd.s, m_textureAreaEnd.t)); // 1,1 by default
            CHECKGL(glVertex3i( m_position.x + m_dimensions.x, m_position.y + m_dimensions.y, 0));      

            CHECKGL(glNormal3i(0,0,1));
            CHECKGL(glTexCoord2f(m_textureAreaStart.s, m_textureAreaEnd.t));  // 0,1 by default
            CHECKGL(glVertex3i( m_position.x, m_position.y + m_dimensions.y,0));
        CHECKGL(glEnd());

        //CHECKGL(glPopMatrix());

        CHECKGL(glDisable(GL_BLEND));
    }

I'm always get an GL_INVALID_OPERATION in glEnd(). I suspect that error is not here, but I can't detect where may be. Actually, the output render seems ok. But I want to solve this situation before to catch a subtle bug tomorrow.

Any idea of what could be

share|improve this question
4  
What is CHECKGL #defined as? –  user744 Jan 14 '11 at 23:02
    
It is a macro in the assert style. If debug, make a glGetError and type error into a log –  Killrazor Jan 16 '11 at 0:05
add comment

1 Answer

up vote 8 down vote accepted

My guess is your CHECKGL macro is calling glGetError between a glBegin/glEnd, which is not one of the defined functions that can be called.

http://www.talisman.org/opengl-1.1/Reference/glEnd.html

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

share|improve this answer
    
You are right. Thank you very much –  Killrazor Jan 14 '11 at 23:21
    
Very counter-intuitive, but true. Those errors are a headache –  Ramon Zarazua Jan 15 '11 at 5:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.