0
我在OpenGL上運行一些教程。我從C開始使用Durian教程,它工作正常。我想將它移植到Java + JOGL(我將爲Android開發,所以我想學習Java下的OpenGL),並且在設置紋理時出現錯誤。「invalid enumerant」after glTexImage2D
的代碼是:
final int[] gl_textures = new int[1];
gl.glGenTextures(1, gl_textures, 0);
int gl_texture = gl_textures[0];
gl.glBindTexture(GL2.GL_TEXTURE_2D, gl_texture);
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_CLAMP_TO_EDGE);
// no error before this
gl.glTexImage2D(gl_texture,
0,
GL2.GL_RGB8,
image.getWidth(),
image.getHeight(),
0,
GL2.GL_BGR,
GL2.GL_UNSIGNED_BYTE,
image.getPixelBuffer()
);
// invalid enumerant here
任何線索什麼可以是錯誤的?
我工作的OpenGL 2.1(我知道,老,但很好學習OpenGL ES)。正如我所說,C教程代碼工作正常。
編輯
下面是渲染代碼。完整版can be found here
private void render(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glUseProgram(m_program);
gl.glUniform1f(m_uniform_fade_factor, (float)(0.5));
gl.glActiveTexture(GL2.GL_TEXTURE0);
gl.glBindTexture(GL2.GL_TEXTURE_2D, m_textures[0]);
gl.glUniform1i(m_uniform_textures[0], 0);
gl.glActiveTexture(GL2.GL_TEXTURE1);
gl.glBindTexture(GL2.GL_TEXTURE_2D, m_textures[1]);
gl.glUniform1i(m_uniform_textures[1], 1);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, m_vertex_buffer);
gl.glVertexAttribPointer(
m_attribute_position,
2,
GL2.GL_FLOAT,
false,
sizeof_float * 2,
0
);
gl.glEnableVertexAttribArray(m_attribute_position);
gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, m_element_buffer);
gl.glDrawElements(
GL2.GL_TRIANGLE_STRIP,
4,
GL2.GL_UNSIGNED_SHORT,
0);
gl.glDisableVertexAttribArray(m_attribute_position);
gl.glFlush();
drawable.swapBuffers();
checkGLError(gl);
}
謝謝,簡單的錯誤。仍然沒有任何顯示在他的屏幕上:( – 2012-03-12 11:04:10
@JakubM。請向我們展示您的繪圖代碼 – datenwolf 2012-03-12 11:27:58
@datenwolf:在這裏,你去!希望你能幫上忙,我試着用和不用'swapBuffers'和'glFlush' – 2012-03-12 15:26:04