Hello guys, recently i ended quake mdl loader, into lwjgl. But i decided to use VBO’s to optimize and speed up models rendering, rather than using only glVertex3f.
My code is the following:
public void renderFrame(int n, boolean hasToRefreshSkin)
{
if ((n < 0) || (n > this.header.numFrames - 1))//Car n démarre à 0
{
System.out.println("n in invalid range !");
return;
}
if(this.texturesID[0] == 0)
{
this.makeTextureFromSkin();
}
else if(hasToRefreshSkin)
this.makeTextureFromSkin();
// glBegin(GL_TRIANGLES);
if(this.buffer == null)
{
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 3; j++)
{
Vertex vert = this.frames[n].verticesArray[this.triangles[i].verticesIndices[j]];
this.vertsList.add((this.header.scale.x * vert.coordinates[0]) + this.header.translate.x);
this.vertsList.add((this.header.scale.y * vert.coordinates[1]) + this.header.translate.y);
this.vertsList.add((this.header.scale.z * vert.coordinates[2]) + this.header.translate.z);
}
}
// float[] array = new float[]
// {
// 0, 2, -4, -2, -2, -4, 2, -2, -4
// };
// float[] array = new float[]
// {
// 86.0F,
// 118.0F,
// 143.0F,
//
// 88.0F,
// 117.0F,
// 145.0F,
//
// 91.0F,
// 119.0F,
// 146.0F,
//
// 86.0F,
// 118.0F,
// 143.0F,
//
// 79.0F,
// 115.0F,
// 149.0F,
//
// 88.0F,
// 117.0F,
// 145.0F
//
// };
float[] array = new float[vertsList.size()];
for(int i = 0; i < array.length; i++)
array[i] = vertsList.get(i);
buffer = BufferUtils.createFloatBuffer(this.header.numVertices * 3 * 4);
buffer.put(array);
buffer.rewind();
// buffer.flip();
}
for(int i = 0; i < this.header.numTriangles; i++)
{
for(int j = 0; j < 3; j++)
{
Vertex vert = this.frames[n].verticesArray[this.triangles[i].verticesIndices[j]];
// float s = this.textureCoordinates[this.triangles[i].verticesIndices[j]].s;
// float t = this.textureCoordinates[this.triangles[i].verticesIndices[j]].t;
// if(this.triangles[i].facesFront == 0 && this.textureCoordinates[this.triangles[i].verticesIndices[j]].onSeam == 1)
// s += this.header.skinWidth * 0.5F;//backface
//
// /* Scale s and t to range from 0.0 to 1.0 */
// s = (s + 0.5F) / this.header.skinWidth;
// t = (t + 0.5F) / this.header.skinHeight;
// glTexCoord2f(s, t);
// glNormal3f(this.normalTable[vert.normalIndex * 3], this.normalTable[(vert.normalIndex * 3) + 1], this.normalTable[(vert.normalIndex * 3) + 2]);
// glVertex3f((this.header.scale.x * vert.coordinates[0]) + this.header.translate.x,
// (this.header.scale.y * vert.coordinates[1]) + this.header.translate.y,
// (this.header.scale.z * vert.coordinates[2]) + this.header.translate.z);
}
}
// glVertex3f((this.header.scale.x * 86) + this.header.translate.x, (this.header.scale.y * 118) + this.header.translate.y, (this.header.scale.z * 143) + this.header.translate.z);
// glVertex3f((this.header.scale.x * 88) + this.header.translate.x, (this.header.scale.y * 117) + this.header.translate.y, (this.header.scale.z * 145) + this.header.translate.z);
// glVertex3f((this.header.scale.x * 91) + this.header.translate.x, (this.header.scale.y * 119) + this.header.translate.y, (this.header.scale.z * 146) + this.header.translate.z);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, 0, buffer);
glDrawArrays(GL_TRIANGLES, 0, this.header.numVertices);
glDisableClientState(GL_VERTEX_ARRAY);
// }
// }
glEnd();
}
But nothing appears on the screen, while glVertex3f works perfectly. Any idea ? Thank you in advance !