Results 1 to 3 of 3
Thread: LWJGL VBO multiple textures
 01242014, 12:51 PM #1Senior Member
 Join Date
 Jan 2013
 Posts
 124
 Rep Power
 0
 01242014, 01:38 PM #2Just a guy
 Join Date
 Jun 2013
 Location
 Netherlands
 Posts
 4,371
 Rep Power
 6
Re: LWJGL VBO multiple textures
Yeah two textures how? Two different textures for two different parts of the model, or are both textures to be applied to all the primitives.
If you have a different texture for different groups of vertices than you can't just load all the vertices and throw them on the same pile, you have to build your model data structure such that you can know which texture to be used for which vertices so you can render them as part of the same batch without having to switch texture for each pair of vertices.
Welcome to 3D game programming  the moment where you realize that this stuff is actually VERY difficult. And also why people tend to use prebuilt engines which deal with this kind of low level stuff for them."Syntactic sugar causes cancer of the semicolon."  Alan Perlis
 01272014, 01:55 PM #3Senior Member
 Join Date
 Jan 2013
 Posts
 124
 Rep Power
 0
Re: LWJGL VBO multiple textures
This is my best result as far as the model itself goes. Textures dont work properly on this.
Java Code:for (int i = 0; i < vertices.size(); i++){ vertexBuffer.put(vertices.get(i).x).put(vertices.get(i).y).put(vertices.get(i).z); vertexBuffer.put(normals.get(i).x). put(normals.get(i).y).put(normals.get(i).z); }
2: And if rendered the model is drawn incorrectly. The code is based around .OBJ file where the line f is something like this 1/7/7. So this connects the vertex with the correct normal and texture. but this doesent work properly.
Java Code:public void prepareVBO(){ vboIndeciesID = glGenBuffers(); vboVertexID = glGenBuffers(); int x = 0; int e = 11; for(int i = 0; i < faces.size(); i++){ total += faces.get(i).size(); } float[] buffer = new float[33 * total]; FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(33* total); IntBuffer indeciesBuffer = BufferUtils.createIntBuffer(33*total); for(int i = 0; i < faces.size(); i++){ for(Face face : faces.get(i)){ Material material = face.material; indeciesBuffer.put((int) (face.vertex.x  1)).put((int) (face.vertex.y  1)).put((int) (face.vertex.z  1)); x = (int) face.vertex.x  1; Vector3f v1 = vertices.get((int) face.vertex.x  1); Vector3f n1 = normals.get((int) face.normal.x 1); Vector2f t1 = texture.get((int) face.texture.x  1); buffer[e*x] = v1.x; buffer[e*x+1] = v1.y; buffer[e*x+2] = v1.z; buffer[e*x+3] = n1.x; buffer[e*x+4] = n1.y; buffer[e*x+5] = n1.z; buffer[e*x+6] = material.getDiffuse().x; buffer[e*x+7] = material.getDiffuse().y; buffer[e*x+8] = material.getDiffuse().z; buffer[e*x+9] = t1.x; buffer[e*x+10] = t1.y; x = (int) face.vertex.y  1; Vector3f v2 = vertices.get((int) face.vertex.y  1); Vector3f n2 = normals.get((int) face.normal.y 1); Vector2f t2 = texture.get((int) face.texture.y  1); buffer[e*x+11] = v2.x; buffer[e*x+12] = v2.y; buffer[e*x+13] = v2.z; buffer[e*x+14] = n2.x; buffer[e*x+15] = n2.y; buffer[e*x+16] = n2.z; buffer[e*x+17] = material.getDiffuse().x; buffer[e*x+18] = material.getDiffuse().y; buffer[e*x+19] = material.getDiffuse().z; buffer[e*x+20] = t2.x; buffer[e*x+21] = t2.y; x = (int) face.vertex.z  1; Vector3f v3 = vertices.get((int) face.vertex.z  1); Vector3f n3 = normals.get((int) face.normal.z 1); Vector2f t3 = texture.get((int) face.texture.z  1); buffer[e*x+22] = v3.x; buffer[e*x+23] = v3.y; buffer[e*x+24] = v3.z; buffer[e*x+25] = n3.x; buffer[e*x+26] = n3.y; buffer[e*x+27] = n3.z; buffer[e*x+28] = material.getDiffuse().x; buffer[e*x+29] = material.getDiffuse().y; buffer[e*x+30] = material.getDiffuse().z; buffer[e*x+31] = t3.x; buffer[e*x+32] = t3.y; } koht.add(indeciesBuffer.position()); } vertexBuffer.put(buffer); indeciesBuffer.rewind(); vertexBuffer.rewind(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndeciesID); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indeciesBuffer, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, vboVertexID); glBufferData(GL_ARRAY_BUFFER, vertexBuffer , GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); }
Similar Threads

LWJGL  Where to go from here
By mitchbutter1210 in forum Advanced JavaReplies: 0Last Post: 06272012, 06:37 AM 
LWJGL help please
By Brandon@JavaForums in forum Advanced JavaReplies: 12Last Post: 12312011, 11:19 AM 
All textures on one .png?
By chrisall76 in forum New To JavaReplies: 0Last Post: 12182011, 12:12 AM 
lwjgl help PLEASE!
By Brandon in forum New To JavaReplies: 1Last Post: 10062011, 07:11 AM 
cannot load textures
By zlatko in forum AWT / SwingReplies: 6Last Post: 02012010, 08:24 PM
Bookmarks