我在IOS 7.0模拟器下使用SDL 2.0.3和OpenglES 1.0 / 2.0有奇怪的行为。 我已将测试应用程序附加到我的github仓库:https://github.com/sabotage3d/gltest 为简单起见,示例是OpenglES 1.0。 当我运行我的测试应用程序时,我得到一个黑屏或有时很大的偏移量。当我开始旋转屏幕时,我可以看到有偏移,箭头没有正确定向,具体取决于屏幕方向。另一个问题是当我继续旋转屏幕时,SDL似乎错过了事件。
以下是代码的一部分:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
SDL_DisplayMode displayMode;
SDL_GetDesktopDisplayMode(0, &displayMode);
SDL_Window* window = SDL_CreateWindow("Orientation", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, displayMode.h, displayMode.w, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN);
SDL_GLContext gl = SDL_GL_CreateContext(window);
glGenRenderbuffersOES(1, &m_renderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_renderbuffer);
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, displayMode.h, displayMode.w);
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);
SDL_Event event;
bool done = false;
while (!done)
{
//Render
glClearColor(0.5f, 0.5f, 0.5f, 1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
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();
SDL_GL_SwapWindow(window);
SDL_PumpEvents();
while (SDL_PollEvent(&event))
{
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED)
{
SDL_Log("Window %d resized to %dx%d",
event.window.windowID, event.window.data1,
event.window.data2);
}
switch (event.type)
{
case SDL_QUIT:
done = true;
break;
}
}
}
答案 0 :(得分:0)
似乎SDL已经提供了删除它们的所有帧缓冲区调用修复了我的问题。 此外,我必须修复相机的宽高比。
这个需要删除的代码:
glGenRenderbuffersOES(1, &m_renderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_renderbuffer);
glGenFramebuffersOES(1, &m_framebuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_framebuffer);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES,
GL_COLOR_ATTACHMENT0_OES,
GL_RENDERBUFFER_OES,
m_renderbuffer);