我目前正在使用LWJGL开发基本的Portal类型游戏。我使用OpenGL的模板缓冲区来绘制通过门户网站看到的世界。我设法让它工作,但当我试图在我的台式电脑而不是我的笔记本电脑上运行时问题出现了。我确保代码完全同步,它仍然在我的桌面上绘制,就像我没有调用
一样glEnable(GL_STENCIL_TEST);
系统信息: 笔记本电脑: CPU:Intel CORE I5。 拉姆:4 Gb。 GPU:英特尔高清显卡 操作系统:Windows 7 Professional 64位 OpenGL:3.1.0
桌面: CPU:Intel CORE I7 拉姆:8 Gb GPU:NVidia GeForce GTX 760 操作系统:Windows 8 Pro 64位 OpenGL:4.4.0
再一次,在我的笔记本电脑上工作正常(它有一个较旧的OpenGL版本),但是我没有在桌面上启用模板测试。
glIsEnabled(GL_STENCIL_TEST);
仍然返回true。
Portal绘图代码(这是在Portal类中):
public static void preparePortalDraw() {
glStencilFunc(GL_NEVER, 0, 0xFF);
glStencilOp(GL_INCR, GL_KEEP, GL_KEEP);
glClear(GL_STENCIL_BUFFER_BIT);
}
public void draw() {
draw3D(model, pos, ang);
}
public static void draw(Portal... portals) {
setRenderMode(A3D); //make sure 3D rendering is enabled
glEnable(GL_STENCIL_TEST);
for (Portal portal : portals) {
preparePortalDraw();
portal.draw(); //draw onto stencil buffer
prepareSceneDraw();
portal.drawScene(); //draw objects as seen through portal
}
clearDepthBuffer();
finishDraw();
for (Portal portal : portals) {
portal.draw(); //draw onto depth buffer
}
//at this point, the scene is drawn normally
}
public static void prepareSceneDraw() {
glColorMask(true, true, true, true);
glDepthMask(true);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glStencilFunc(GL_LEQUAL, 1, 0xFF);
}
public void drawScene() {
if (linked != null) {
pushMatrix();
translate(pos);
rotateY(ang.yaw - linked.ang.yaw - 180); //linked is the portal paired with this one
translate(Vector3.negate(linked.pos));
for (Entity e : worldGeom) {
e.draw();
}
popMatrix();
}
}
public static void finishDraw() {
glDisable(GL_STENCIL_TEST);
}
设置渲染上下文的代码(在每个帧的开头调用,以A3D为参数):
public static void setRenderMode(RenderMode mode) {
if (mode == AspectRenderer.mode) {
return;
}
if (mode == RenderMode.A3D) {
glViewport(0, 0, getWidth(), getHeight());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float aspect = (float) getWidth() / (float) getHeight();
gluPerspective(60, aspect, 0.1f, 1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel(GL_SMOOTH);
glEnable(GL_CULL_FACE);
glFrontFace(GL_CCW);
setupCamera();
} else {
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, getCanvasWidth(), 0, getCanvasHeight());
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
AspectRenderer.mode = mode;
}
非常确定这不是我的代码的问题,考虑到它在OpenGL 3上运行良好,但是有什么我应该知道的OpenGL 4可以打破这个吗?