我正在修改帧缓冲区,突然有东西坏了,一切恢复正常后我又回到状态,然后OpenGL突然停止了渲染。我可以碰巧glClearColor
,也可以使用glBegin渲染东西,但是使用着色器和glDrawElements
渲染时我什么也没有。我解除了每个帧缓冲区的绑定,检查了项目中的每个类,检查了着色器,什么也没有。
package test;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.ContextAttribs;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.PixelFormat;
import org.lwjgl.util.vector.Vector2f;
public class Main {
public static World world;
public static GUIRenderer renderer;
public static FrameBuffer buffer;
public static void main(String[] args) throws InterruptedException {
try {
ContextAttribs attributes = new ContextAttribs(3,2).withForwardCompatible(true).withProfileCore(true);
Display.setDisplayMode(new DisplayMode(800, 600));
Display.setTitle("Test");
Display.create(new PixelFormat(), attributes);
} catch(LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
world = new World();
Vector2f[] vec = {new Vector2f(-1, 1), new Vector2f(-1, -1), new Vector2f(1, -1), new Vector2f(1, 1)};
int[] indices = {0, 1, 2, 0, 2, 3};
Mesh mesh = new Mesh();
mesh.load(vec, indices);
BasicShader2D shader = new BasicShader2D();
renderer = new GUIRenderer();
buffer = new FrameBuffer();
GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());
while(!Display.isCloseRequested()) {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glClearColor(0.5f, 0, 0, 1);
GL11.glEnable(GL11.GL_TEXTURE_2D);
//buffer.bind();
world.tick();
renderer.render(mesh, shader);
//buffer.unbind();
GL11.glDisable(GL11.GL_TEXTURE_2D);
Display.update();
Thread.sleep(16);
}
world.delete();
Display.destroy();
}
}
//vertex
#version 150 core
uniform mat4 transformation;
uniform mat4 projection;
uniform mat4 view;
in vec3 pos;
in vec3 normal;
void main() {
gl_Position = projection * view * transformation * vec4(pos, 1.0);
}
//fragment
#version 150 core
//#define PI 3.1415926535897932384626433832795
out vec4 color_out;
void main(){
color_out = vec4(1.0, 1.0, 0.0, 1.0);
}