Hello,
I'm currently porting this tutorial to LWJGL :
http://www.arcsynthesis.org/gltut/Basics/Tutorial%2001.htmlEverything seems to be going fine, i can create and load the Shaders without issue, but when i go to draw the triangle on the screen, it remains black with no visible triangle.
Some code fragments :
Create the VBO :
package com.maoni.shaders.util;
import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import static org.lwjgl.opengl.GL15.*;
public enum InitializeVertexBuffer {
INSTANCE,
;
public int createPositionBufferObject(float vertices[]) {
int positionBufferObject = glGenBuffers();
FloatBuffer fb = BufferUtils.createFloatBuffer(vertices.length);
fb.put(vertices);
fb.flip();
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
glBufferData(positionBufferObject, fb, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
return positionBufferObject;
}
}
Initialise the Shaders etc :
private static void init() {
try {
int width = 800;
int height = 600;
Display.setDisplayMode(new DisplayMode(width, height));
Display.setVSyncEnabled(true);
Display.setTitle("Maoni V0.01");
Display.create();
// Setup the shader program
shaderList.add(CreateShader.VERTEX.load(_VERTEX_SHADER_LOCATION));
shaderList.add(CreateShader.FRAGMENT.load(_FRAGMENT_SHADER_LOCATION));
_PROGRAM = CreateProgram.INSTANCE.create(shaderList);
// Setup the PositionBufferObject
_PBO = InitializeVertexBuffer.INSTANCE.createPositionBufferObject(vertexPositions);
glViewport(0, 0, width, height);
} catch (LWJGLException e) {
e.printStackTrace();
}
}
And then try and Draw it :
private static void render() {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(_PROGRAM);
glBindBuffer(GL_ARRAY_BUFFER, _PBO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, false, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glUseProgram(0);
Display.update();
}
The whole code is listed here :
https://github.com/Almclean/MaoniIf anyone could point me in the right direction i would be very grateful.
Many thanks,
M