我正在 Android 上编写 OpenGL ES 1.1 应用程序(所有OpenGL ES代码都是C ++ )。
在模拟器上测试它工作正常,但是当我在真实设备(HTC Desire)上测试它时,它不起作用(我只看到黑屏)。
这是我的OpenGL C ++代码:
RenderingEngine1::RenderingEngine1()
{
// Create & bind the color buffer so that the caller can allocate its space.
glGenRenderbuffersOES(1, &m_renderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_renderbuffer);
}
void RenderingEngine1::Initialize(int width, int height)
{
// Create the framebuffer object and attach the color buffer.
glGenFramebuffersOES(1, &m_framebuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_framebuffer);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES,
GL_COLOR_ATTACHMENT0_OES,
GL_RENDERBUFFER_OES,
m_renderbuffer);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
// Initialize the projection matrix.
const float maxX = 2;
const float maxY = 3;
glOrthof(-maxX, +maxX, -maxY, +maxY, -1, 1);
glMatrixMode(GL_MODELVIEW);
// Initialize the rotation animation state.
OnRotate(DeviceOrientationPortrait);
m_currentAngle = m_desiredAngle;
}
void RenderingEngine1::Render() const
{
glClearColor(0.5f, 0.5f, 0.5f, 1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(m_currentAngle, 0, 0, 1);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(2, GL_FLOAT, sizeof(Vertex), &Vertices[0].Position[0]);
glColorPointer(4, GL_FLOAT, sizeof(Vertex), &Vertices[0].Color[0]);
GLsizei vertexCount = sizeof(Vertices) / sizeof(Vertex);
glDrawArrays(GL_TRIANGLES, 0, vertexCount);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glPopMatrix();
}
JNI方法在这个C ++代码中:
extern "C" {
IRenderingEngine* m_renderingEngine;
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
{
return JNI_VERSION_1_4;
}
void Java_com_company_tests_MainRenderer_nativeInit( JNIEnv* env, jobject thiz )
{
m_renderingEngine = CreateRenderer1();
m_renderingEngine->Initialize(480, 800);
}
void Java_com_company_tests_MainRenderer_nativeRender( JNIEnv* env, jobject thiz )
{
m_renderingEngine->Render();
}
}
我还有两个Java类:一个继承自 GLSurfaceView ,一个实现 GLSurfaceView.Renderer 的渲染器。
我不知道为什么它不适用于真实设备。
有什么建议吗?
如果您还需要别的东西,请告诉我。