Moin,
ich habe mir das gerade mal versucht anzusehen. Aber ich kann kein RAR öffnen (unfrei) und in den 36 MB habe ich dann leider auch kein KSKB gefunden.
Ein KSKB zu Deinem Problem sollte etwa so aussehen:
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_FALSE;
import static org.lwjgl.opengl.GL11.GL_FLOAT;
import static org.lwjgl.opengl.GL11.GL_TRIANGLE_STRIP;
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_SHORT;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glDrawElements;
import static org.lwjgl.opengl.GL15.GL_ARRAY_BUFFER;
import static org.lwjgl.opengl.GL15.GL_ELEMENT_ARRAY_BUFFER;
import static org.lwjgl.opengl.GL15.GL_STATIC_DRAW;
import static org.lwjgl.opengl.GL15.glBindBuffer;
import static org.lwjgl.opengl.GL15.glBufferData;
import static org.lwjgl.opengl.GL15.glDeleteBuffers;
import static org.lwjgl.opengl.GL15.glGenBuffers;
import static org.lwjgl.opengl.GL20.GL_COMPILE_STATUS;
import static org.lwjgl.opengl.GL20.GL_FRAGMENT_SHADER;
import static org.lwjgl.opengl.GL20.GL_INFO_LOG_LENGTH;
import static org.lwjgl.opengl.GL20.GL_LINK_STATUS;
import static org.lwjgl.opengl.GL20.GL_VERTEX_SHADER;
import static org.lwjgl.opengl.GL20.glAttachShader;
import static org.lwjgl.opengl.GL20.glCompileShader;
import static org.lwjgl.opengl.GL20.glCreateProgram;
import static org.lwjgl.opengl.GL20.glCreateShader;
import static org.lwjgl.opengl.GL20.glEnableVertexAttribArray;
import static org.lwjgl.opengl.GL20.glGetProgramInfoLog;
import static org.lwjgl.opengl.GL20.glGetProgrami;
import static org.lwjgl.opengl.GL20.glGetShaderInfoLog;
import static org.lwjgl.opengl.GL20.glGetShaderi;
import static org.lwjgl.opengl.GL20.glLinkProgram;
import static org.lwjgl.opengl.GL20.glShaderSource;
import static org.lwjgl.opengl.GL20.glUseProgram;
import static org.lwjgl.opengl.GL20.glVertexAttribPointer;
import static org.lwjgl.opengl.GL30.glBindVertexArray;
import static org.lwjgl.opengl.GL30.glDeleteVertexArrays;
import static org.lwjgl.opengl.GL30.glGenVertexArrays;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.ContextAttribs;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.PixelFormat;
public final class GL33Circle {
private static final int WIDTH = 1200;
private static final int HEIGHT = 800;
private static final int GL_MAJOR_VERSION = 3;
private static final int GL_MINOR_VERSION = 3;
private static final int VERTEX_COORD_LOCATION = 0;
private static final int TEXTURE_COORD_LOCATION = 1;
private static final String VERTEX_SHADER = ""
+ "#version 330
"
+ "
"
+ "layout(location = " + VERTEX_COORD_LOCATION + ") in vec3 v;
"
+ "layout(location = " + TEXTURE_COORD_LOCATION + ") in vec2 vt;
"
+ "
"
+ "out vec2 fvt;
"
+ "
"
+ "void main() {
"
+ "
"
+ " fvt = vt;
"
+ " gl_Position = vec4(v.xyz * 0.5, 1);
"
+ "
"
+ "}
";
private static final String FRAGMENT_SHADER = ""
+ "#version 330
"
+ "
"
+ "in vec2 fvt;
"
+ "
"
+ "out vec4 color;
"
+ "
"
+ "void main() {
"
+ "
"
+ " float len = length(fvt - vec2(0.5, 0.5));
"
+ "
"
+ " if(len < 0.5)
"
+ " color = vec4(1, 1, 1, 1);
"
+ "
"
+ " else
"
+ " color = vec4(1, 0, 0, 1);
"
+ "
"
+ "}
";
private static final short[] QUAD_IBO = new short[] { 1, 2, 0, 3 };
// x, y, z, s, t
private static final float[] QUAD_VBO = new float[] {
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
+1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
+1.0f, +1.0f, 0.0f, 1.0f, 1.0f,
-1.0f, +1.0f, 0.0f, 0.0f, 1.0f,
};
private int handleVAO;
private int handleIBO;
private int handleVBO;
public static void main(final String[] args) throws LWJGLException {
final DisplayMode displayMode = new DisplayMode(WIDTH, HEIGHT);
final PixelFormat pixelFormat = new PixelFormat();
final ContextAttribs contextAttribs = new ContextAttribs(GL_MAJOR_VERSION, GL_MINOR_VERSION).withProfileCore(true);
new GL33Circle().run(displayMode, pixelFormat, contextAttribs);
}
void run(final DisplayMode displayMode, final PixelFormat pixelFormat, final ContextAttribs contextAttribs) throws LWJGLException {
Display.setDisplayMode(displayMode);
Display.create(pixelFormat, contextAttribs);
Display.setVSyncEnabled(true);
glInit();
while (!Display.isCloseRequested()) {
glDisplay();
Display.update();
}
glDispose();
Display.destroy();
}
private void glInit() {
glInitVAO();
glInitIBO();
glInitVBO();
glInitShader();
}
private void glInitVAO() {
handleVAO = glGenVertexArrays();
glBindVertexArray(handleVAO);
}
private void glInitIBO() {
final ShortBuffer buffer = BufferUtils.createShortBuffer(QUAD_IBO.length);
buffer.put(QUAD_IBO);
buffer.flip();
handleIBO = glGenBuffers();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, handleIBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
}
private void glInitVBO() {
final FloatBuffer buffer = BufferUtils.createFloatBuffer(QUAD_VBO.length);
buffer.put(QUAD_VBO);
buffer.flip();
handleVBO = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, handleVBO);
glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
glEnableVertexAttribArray(VERTEX_COORD_LOCATION);
glVertexAttribPointer(VERTEX_COORD_LOCATION, 3, GL_FLOAT, false, Float.BYTES * 5, 0);
glEnableVertexAttribArray(TEXTURE_COORD_LOCATION);
glVertexAttribPointer(TEXTURE_COORD_LOCATION, 2, GL_FLOAT, false, Float.BYTES * 5, Float.BYTES * 3);
}
private void glInitShader() {
final int vs = buildShader(GL_VERTEX_SHADER, VERTEX_SHADER);
final int fs = buildShader(GL_FRAGMENT_SHADER, FRAGMENT_SHADER);
final int p = buildProgram(vs, fs);
glUseProgram(p);
}
private int buildShader(final int type, final String source) {
final int handle = glCreateShader(type);
glShaderSource(handle, source);
glCompileShader(handle);
if (GL_FALSE == glGetShaderi(handle, GL_COMPILE_STATUS)) {
final int length = glGetShaderi(handle, GL_INFO_LOG_LENGTH);
final String log = glGetShaderInfoLog(handle, length);
throw new RuntimeException(log);
}
return handle;
}
private int buildProgram(final int... shaders) {
final int handle = glCreateProgram();
for (final int shader : shaders)
glAttachShader(handle, shader);
glLinkProgram(handle);
if (GL_FALSE == glGetProgrami(handle, GL_LINK_STATUS)) {
final int length = glGetProgrami(handle, GL_INFO_LOG_LENGTH);
final String log = glGetProgramInfoLog(handle, length);
throw new RuntimeException(log);
}
return handle;
}
private void glDisplay() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawElements(GL_TRIANGLE_STRIP, QUAD_IBO.length, GL_UNSIGNED_SHORT, 0);
}
private void glDispose() {
glDeleteBuffers(handleVBO);
glDeleteBuffers(handleIBO);
glDeleteVertexArrays(handleVAO);
}
}
Gruß
Fancy