what I think is important in the main
[spoiler]
public void init(){
try {
PF = new PixelFormat(8, 16, 0, 16);
Display.setDisplayMode(new DisplayMode(width, height));
Display.setVSyncEnabled(true);
Display.create(PF);
} catch (LWJGLException e) {
e.printStackTrace();
}
lastFps = getTime();
setupGL();
screen.init();
splashscreen.init();
}
public void setupGL(){
glMatrixMode(GL_PROJECTION);
//glOrtho(0, width, height, 0, 1, -1);
glViewport(0, 0, Display.getWidth(), Display.getHeight());
gluPerspective(50f, (float)800 / (float)600, 1, 1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glRotatef(-35f, 1.0f, 0.0f, 0.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
}
[/spoiler]
my vbo class I know Its a mess sorry
[spoiler]
public class Quad3DVBO extends VBO{
protected int instances = 0;
public Quad3DVBO(){
}
public Quad3DVBO(Color color){
this.color = color;
colored = true;
numberOfID += 1;
}
public Quad3DVBO(SpriteSheet sheet, Textures texture){
this.sheet = sheet;
this.texture = texture;
textured = true;
numberOfID += 1;
}
public void add(float[] coords){
setVertices(coords);
if(colored){
setColors();
}
}
public void add(Block block){
for(float[] v : block.getVerices()){
setVertices(v);
if(colored){
setColors();
}
if(textured){
setTextures();
}
}
}
public void add(Block block, float x, float y, float z){
for(float[] v : block.getVerices(x, y, z)){
setVertices(v);
}
if(colored){
setColors();
}
for(float[] t : block.getTextures()){
if(textured){
setTextures(t);
}
}
}
public void add(float[] coords, float[] cols){
setVertices(coords);
if(colored){
setColors(cols);
}
}
public void init() {
buffIds = BufferUtils.createIntBuffer(numberOfID);
glGenBuffers(buffIds);
vertexId = buffIds.get(0);
indexId = buffIds.get(1);
if(colored){
colorId = buffIds.get(2);
}
if(textured){
textureCoordsId = buffIds.get(2);
}
vertexBuff = BufferUtils.createFloatBuffer(12*instances);
for(float[] v : vertices){
vertexBuff.put(v);
}
indexBuff = BufferUtils.createShortBuffer(6*instances);
for(short[] i : indices){
indexBuff.put(i);
}
if(colored){
colorBuff = BufferUtils.createFloatBuffer(16*instances);
for(float[] c : colors){
colorBuff.put(c);
}
colorBuff.flip();
glBindBuffer(GL_ARRAY_BUFFER, colorId);
glBufferData(GL_ARRAY_BUFFER, colorBuff, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
if(textured){
textureBuff = BufferUtils.createFloatBuffer(8 * instances);
for(float[] t : textures){
textureBuff.put(t);
}
textureBuff.flip();
glBindBuffer(GL_ARRAY_BUFFER, textureCoordsId);
glBufferData(GL_ARRAY_BUFFER, textureBuff, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
vertexBuff.flip();
glBindBuffer(GL_ARRAY_BUFFER, vertexId);
glBufferData(GL_ARRAY_BUFFER, vertexBuff, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
indexBuff.flip();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexId);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexBuff, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
public void render() {
glPushMatrix();
//glShadeModel(GL_SMOOTH);
if(textured){
glBindTexture(GL_TEXTURE_2D, sheet.getTextureID());
}
glCullFace(GL_FRONT);
glTranslatef(x, y, z);
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, vertexId);
glVertexPointer(3, GL_FLOAT, 0, 0);
if(colored){
glEnableClientState(GL_COLOR_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, colorId);
glColorPointer(4, GL_FLOAT, 0, 0);
}
if(textured){
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, textureCoordsId);
glTexCoordPointer(2, GL_FLOAT, 0, 0l);
}
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexId);
glDrawElements(GL_TRIANGLES, indexBuff.capacity(), GL_UNSIGNED_SHORT, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
if(colored){
glDisableClientState(GL_COLOR_ARRAY);
}
if(textured){
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
glDisableClientState(GL_VERTEX_ARRAY);
if(textured){
glBindTexture(GL_TEXTURE_2D, 0);
}
glPopMatrix();
}
public void dispose(){
buffIds.put(0, vertexId);
buffIds.put(1, indexId);
if(colored){
buffIds.put(2, colorId);
}
if(textured){
buffIds.put(2, textureCoordsId);
}
glDeleteBuffers(buffIds);
}
public void translate(float x, float y, float z){
this.x += x;
this.y += y;
this.z += z;
}
private void setVertices(float[] vert){
if(vert.length == 12)
{
short indpos = (short)(instances*4);
vertices.add(vert);
indices.add(new short[]{(short)(indpos+2), (short)(indpos+1), indpos, indpos, (short)(indpos+3), (short)(indpos+2)});
instances++;
}else{
System.out.println("ERROR - The array must containt 12 variables.");
}
}
private void setColors(){
float[] vertexCols = new float[16];
float[] toArray = color.getColors();
for(int i = 0; i <= 3; i++){
vertexCols[i*4] = toArray[0];
vertexCols[i*4+1] = toArray[1];
vertexCols[i*4+2] = toArray[2];
vertexCols[i*4+3] = toArray[3];
}
colors.add(vertexCols);
}
private void setColors(float[] cols){
float[] vertexCols = new float[16];
for(int i = 0; i <= 3; i++){
vertexCols[i*4] = cols[0];
vertexCols[i*4+1] = cols[1];
vertexCols[i*4+2] = cols[2];
vertexCols[i*4+3] = cols[3];
}
colors.add(vertexCols);
}
private void setTextures(){
float[] toArray = texture.getCoords();
textures.add(toArray);
}
private void setTextures(float[] coords){
textures.add(coords);
}
}
[/spoiler]
initializing my sprite sheet
[spoiler]
public void init(){
textureID = glGenTextures();
glBindTexture(GL_TEXTURE_2D, textureID); //Bind texture ID
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
glBindTexture(GL_TEXTURE_2D, 0);
}
[/spoiler]