glTexEnv返回无法解释的INVALID_OPERATION ERROR

时间:2010-11-25 10:39:16

标签: opengl glsl shader

问题:

紧跟“glTexEnvi(GL_POINT_SPRITE,GL_COORD_REPLACE,GL_TRUE);”我得到了GL ERROR#1282(INVALID_OPERATION)。

然后当我查阅OpenGL 2.1 Reference时,在glTexEnv下说:如果在执行glBegin和glEnd的相应执行之间执行glTexEnv,则会生成GL_INVALID_OPERATION。 这不是我的情况,因为我使用的是顶点数组。

这是我的代码的一部分:

void RBFS::render_pass1_point_sprites(Shader &shader1, int width, int height, float t)
{
 shader1.bind();

 glActiveTexture(GL_TEXTURE0);{
  glBindTexture(GL_TEXTURE_1D, m_texRBFData[0]);
  MyCheckErrorGL();
 }
 glActiveTexture(GL_TEXTURE1);{
  glBindTexture(GL_TEXTURE_1D, m_texRBFData[1]);
  MyCheckErrorGL();
 }
 glActiveTexture(GL_TEXTURE2);{
  glBindTexture(GL_TEXTURE_3D, m_texSDF);
  MyCheckErrorGL();
 }
 glActiveTexture(GL_TEXTURE3);{
  glBindTexture(GL_TEXTURE_3D, m_texLabels[0]);
  MyCheckErrorGL();
 }
 glActiveTexture(GL_TEXTURE4);{
  glBindTexture(GL_TEXTURE_3D, m_texLabels[1]);
  MyCheckErrorGL();
 } 
 glActiveTexture(GL_TEXTURE5);{
  glBindTexture(GL_TEXTURE_1D, m_texHG);
  MyCheckErrorGL();
 }
 glActiveTexture(GL_TEXTURE9);{
  glBindTexture(GL_TEXTURE_2D, m_texCircle);
  MyCheckErrorGL();
 }

 // upload t
 GLuint loc_t = my_glGetUniformLocation(shader1.id(), "tSlice");
 glUniform1f(loc_t, t);
 MyCheckErrorGL();

 // SET POINT_SPRITE
 glEnable(GL_POINT_SPRITE);
        glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);// so we can set different point size in VShader
 float sizes[2];
 glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, sizes);
 glPointParameterf(GL_POINT_SIZE_MIN, sizes[0]);
 glPointParameterf(GL_POINT_SIZE_MAX, sizes[1]);
 MyCheckErrorGL();
 glTexEnvi( GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);// means tex-coord iteration
 MyCheckErrorGL();
 glPointParameterfARB(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);// set origin-y
 MyCheckErrorGL();
 glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST);
 MyCheckErrorGL();

 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_density);{

  glPushAttrib(GL_VIEWPORT_BIT);
  glViewport(0, 0, width, height);

  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glLoadIdentity();

  glClearColor(0.0,0.0,0.0,1.0);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  MyCheckErrorGL();

  glDrawArrays(GL_POINTS, 0, numRBFs);//3rd parameter: number of points
  MyCheckErrorGL();

  glDisable(GL_BLEND);
  glPopMatrix();
  glPopAttrib();
 }
 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

 // turn off switches for PSprite
 glDisable(GL_POINT_SPRITE);
 glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);

 MyCheckErrorGL();

 glActiveTexture(GL_TEXTURE9);
 glBindTexture(GL_TEXTURE_2D, 0);
 glActiveTexture(GL_TEXTURE5);
 glBindTexture(GL_TEXTURE_1D, 0);
 glActiveTexture(GL_TEXTURE4);
 glBindTexture(GL_TEXTURE_3D, 0);
 glActiveTexture(GL_TEXTURE3);
 glBindTexture(GL_TEXTURE_3D, 0);
 glActiveTexture(GL_TEXTURE2);
 glBindTexture(GL_TEXTURE_3D, 0);
 glActiveTexture(GL_TEXTURE1);
 glBindTexture(GL_TEXTURE_1D, 0);
 glActiveTexture(GL_TEXTURE0);
 glBindTexture(GL_TEXTURE_1D, 0);

 shader1.unbind();
 MyCheckErrorGL();
}

因为我是OpenGL的绿色手。如果您对我的代码有其他建议,请不要犹豫告诉我。: - )

2 个答案:

答案 0 :(得分:1)

听起来您的OpenGL设备根本不支持POINT_SPRITE。

GL 2.0规范集成了点精灵作为核心功能。您的设备支持哪种GL版本?

答案 1 :(得分:1)

阅读glTexEnv reference page,它说:

  

如果在执行glBegin和glEnd的相应执行之间执行glTexEnv,则会生成GL_INVALID_OPERATION。

它也说:

  

GL_POINT_SPRITE和GL_COORD_REPLACE仅在GL版本为2.0或更高版本时可用。

你确定你的卡或驱动程序支持opengl 2.0吗?