Ok, thanks for the advices. I’ll start looking into it, but first i would like to make it work in order to continue on other features.
I Wrote a small thing that should draw a single triangle with an texture on it but all i have is an empty black window. Can anybody see what i am doing wrong and (maybe) if this is even worst than i did before ?
public class Triangles {
private Texture texture;
private FloatBuffer textureData;
private Vector3f position, rotation;
private int vboVertexHandleChunk;
private FloatBuffer interleavedBuffer;
private int floatByteSize = 4;
private int positionFloatCount = 3;
private int floatsPerVertex = positionFloatCount*2;
private int texId;
public Triangles(){
this.initDisplay();
this.openGL();
position = new Vector3f(0f, 0, 0);
rotation = new Vector3f(0, 0, 0);
}
public static void main(String[] args) {
Triangles test = new Triangles();
test.openImage();
test.renderLoop();
}
private void openGL(){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(50, 800/600, 0.01f, 20);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glLoadIdentity();
}
public void initDisplay(){
try{
Display.setResizable(true);
Display.setDisplayMode(new DisplayMode((int)800, (int)600));
Display.setTitle("Dino Survive");
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
Display.destroy();
System.exit(1);
}
Mouse.setGrabbed(false);
}
private void renderLoop(){
genCubes();
while(!Display.isCloseRequested()){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
useView();
input();
drawCube();
Display.sync(60);
Display.update();
}
Display.destroy();
}
private void openImage(){
try {
texture = TextureLoader.getTexture("PNG",
ResourceLoader.getResourceAsStream("../DinoSurvive/res/text.png"));
} catch (IOException e) {
e.printStackTrace();
}
textureData = BufferUtils.createFloatBuffer(3 * 2);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
private void useView(){
glRotatef(rotation.x, 1, 0, 0);
glRotatef(rotation.y, 0, 1, 0);
glRotatef(rotation.z, 0, 0, 1);
glTranslatef(position.x, position.y, position.z);
System.out.println(position);
}
private void genCubes(){
vboVertexHandleChunk = GL15.glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandleChunk);
interleavedBuffer = BufferUtils.createFloatBuffer(3*2+3*3);
interleavedBuffer.put(new float[]{
0, 0, 3, 0.03125f+0, 0.03125f+0,
-1, 0, 3, 0.03125f+0, 0+0,
-1, -1, 3, 0+0, 0.03125f+0});
interleavedBuffer.flip();
glBufferData(GL_ARRAY_BUFFER, interleavedBuffer, GL_STATIC_DRAW);
}
private void drawCube(){
glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandleChunk);
//glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 5*4, 0L);
glClientActiveTexture(GL_TEXTURE0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 5*4, 3*4 );
glDrawArrays(GL_TRIANGLES, 0, 6);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
}
I remove some of the method to make the code a little less longer.
One again, thank you for reading and caring !