IM tryign寫一個腳本3D對象,以顯示使用JOGL 2使用OpenGL 3.3基本的3D對象/多邊形三角形然而,當項目編譯我收到任何錯誤,並得到一個對象出現的空白窗口。所以我的問題是,有什麼具體的IM中添加,使出現..我的代碼如下目標丟失...如何顯示使用JOGL 2指數用OpenGL 3.3
public void init(GL3 gl)
{
gl.glGenVertexArrays(1, IntBuffer.wrap(temp));
//create vertice buffers
int vao = temp[0];
gl.glBindVertexArray(vao);
gl.glGenBuffers(1, IntBuffer.wrap(temp));
int[] temp2 = new int[]{1,1};
gl.glGenBuffers(2, IntBuffer.wrap(temp2));
vbo = temp2[0];
ebo = temp2[1];
//creates vertex array
float vertices[] = {
-0.5f, 0.5f, 0.0f,//1,0,0, // Top-left
0.5f, 0.5f, 0.0f,//0,1,0, // Top-right
0.5f, -0.5f, 0.0f,//0,0,1, // Bottom-right
-0.5f, -0.5f, 0.0f//1,1,0 // Bottom-left
};
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo);
gl.glBufferData(GL.GL_ARRAY_BUFFER, vertices.length * 4,
FloatBuffer.wrap(vertices), GL.GL_STATIC_DRAW);
//creates element array
int elements[] = {
0,1,2,
2,3,0
};
gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, ebo);
gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, elements.length * 4,
IntBuffer.wrap(elements), GL.GL_STATIC_DRAW);
gl.glVertexAttribPointer(0, 3, GL.GL_FLOAT, false, 3*4, 0* 4);
gl.glEnableVertexAttribArray(0);
}
public void draw(GL3 gl)
{
gl.glBindVertexArray(vao);
gl.glDrawElements(GL.GL_TRIANGLES, 2, GL.GL_UNSIGNED_INT, 0);
}
至於正在啓動我的着色器,其中,它在不同的類,這是如下..
//Matrix4 view = new Matrix4(MatrixFactory.perspective(scene.camera.getHeightAngle(),scene.camera.getAspectRatio(),scene.camera.getPosition());
projection = MatrixFactory.perspective(scene.camera.getHeightAngle(), scene.camera.getAspectRatio(), 0.01f, 100f);
view = MatrixFactory.lookInDirection(scene.camera.getPosition(), scene.camera.getDirection(), scene.camera.getUp());
try {
shader = new Shader(new File("shaders/Transform.vert"), new File("shaders/Transform.frag"));
shader.compile(gl);
shader.enable(gl);
shader.setUniform("projection", projection, gl);
shader.setUniform("view", view, gl);
}
catch (Exception e) {
System.out.println("message " + e.getMessage());
}
for (Shape s : scene.shapes) {
s.init(gl);
}
最後,我着色器文件
#version 330
out vec4 fragColour;
//in vec3 outColour;
void main() {
fragColour = vec4(1,0,0,1);
}
#version 330
uniform mat4 projection;
uniform mat4 view;
layout(location=0) in vec3 pos;
//layout(location=2) in vec2 texCoord;
//layout(location=1) in vec3 colours;
out vec2 fragTex;
out vec3 outColour;
vec4 newPos;
void main() {
newPos = vec4(pos,1.0);
gl_Position = projection * view * newPos;
//fragTex = texCoord;
//outColour = colours;
}
我是在我要去的地方錯了,無論是着色器文件,或者actualy代碼本身不能確定。 。
您使用的頂點和索引數據相同的緩衝區,因爲您分配相同的值'vbo'和'ebo'需要。 – 2014-10-01 05:43:08
沒有3.3。目前(2014年),它被稱爲JOGL 2. JOGL版本與OpenGL版本不匹配。此外,通過查看我們的工作示例(包括RedSquareES2)以及像往常一樣在官方論壇上提出這個問題,您會浪費更少的時間。 – gouessej 2014-10-01 17:52:40