1
\$\begingroup\$

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

\$\endgroup\$
  • 4
    \$\begingroup\$ What is CHECKGL #defined as? \$\endgroup\$ – user744 Jan 14 '11 at 23:02
  • \$\begingroup\$ It is a macro in the assert style. If debug, make a glGetError and type error into a log \$\endgroup\$ – Killrazor Jan 16 '11 at 0:05
8
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ Very counter-intuitive, but true. Those errors are a headache \$\endgroup\$ – Ramon Zarazua B. Jan 15 '11 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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