这是我的代码,我找不到问题隐藏在哪里。
bool setupGraphics(int w, int h) {
printGLString("Version", GL_VERSION);
printGLString("Vendor", GL_VENDOR);
printGLString("Renderer", GL_RENDERER);
printGLString("Extensions", GL_EXTENSIONS);
glViewport(0, 0, w, h);
checkGlError("glViewport");
glEnable(GL_DEPTH_TEST);
LOGI("setupGraphics(%d, %d)", w, h);
gProgram = createProgram(gVertexShader, gFragmentShader);
if (!gProgram) {
LOGE("Could not create program.");
return false;
}
gvPositionHandle = glGetAttribLocation(gProgram, "vPosition");
checkGlError("glGetAttribLocation");
//Init texture.
makeCheckImage();
checkGlError("init texture1");
glGenTextures(1, gTextureHandler);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
glBindTexture(GL_TEXTURE_2D, gTextureHandler[0]);
checkGlError("init texture2");
gTextureUniformHandler = glGetUniformLocation(gProgram, "uTexture");
gTextureCoordinateHandler = glGetAttribLocation(gProgram, "vTexCoordinate");
checkGlError("init texture");
return true;
}
日志:
I/libgl2jni(30066): GL Version = OpenGL ES 2.0 build 1.8.GOOGLENEXUS.ED945322@2112805
I/libgl2jni(30066): GL Vendor = Imagination Technologies
I/libgl2jni(30066): GL Renderer = PowerVR SGX 540
I/libgl2jni(30066): GL Extensions = GL_EXT_debug_marker GL_OES_rgb8_rgba8 GL_OES_depth24 GL_OES_vertex_half_float GL_OES_texture_float GL_OES_texture_half_float GL_OES_element_index_uint GL_OES_mapbuffer GL_OES_fragment_precision_high GL_OES_compressed_ETC1_RGB8_texture GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_required_internalformat GL_OES_depth_texture GL_OES_get_program_binary GL_OES_packed_depth_stencil GL_OES_standard_derivatives GL_OES_vertex_array_object GL_OES_egl_sync GL_EXT_multi_draw_arrays GL_EXT_texture_format_BGRA8888 GL_EXT_discard_framebuffer GL_EXT_shader_texture_lod GL_IMG_shader_binary GL_IMG_texture_compression_pvrtc GL_IMG_texture_npot GL_IMG_texture_format_BGRA8888 GL_IMG_read_format GL_IMG_program_binary GL_IMG_multisampled_render_to_texture
I/libgl2jni(30066): setupGraphics(480, 800)
I/libgl2jni(30066): after init texture2() glError (invalide operation)
如果我评论glTexImage2D(GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
glBindTexture(GL_TEXTURE_2D, gTextureHandler[0]);
那么一切都会顺利。
答案 0 :(得分:1)
您的glBindTexture
和glTexImage
输入错误。 glTexImage更新当前绑定到指定目标的纹理。
首先绑定纹理,然后填充数据。此外,您应该在设置min / mag滤镜之前绑定纹理,因为这些也会修改绑定纹理。
答案 1 :(得分:-1)
我自己解决了这个问题。该错误是由glTexImage2D
中的不一致参数引起的。如果我将其更改为glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
,则错误不存在。