![](/img/trans.png)
[英]OpenGL - how to render object to 3D texture as a volumetric billboard
[英]How to apply a texture on a 3D object in OpenGL
我嘗試將紋理(png文件)應用於以Java導入的3d對象。 這是我的代碼,我想我沒有正確地做。
渲染塊:
while (!Display.isCloseRequested()){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT
glPushMatrix();
glNewList(treeDisplayList, GL_COMPILE);
Model m = null;
try {
m = OBJLoader.loadModel(new File(ObjectConstants.tree));
} catch (FileNotFoundException e) {
e.printStackTrace();
Display.destroy();
System.exit(1);
} catch (IOException e) {
e.printStackTrace();
Display.destroy();
System.exit(1);
}
glBegin(GL_TRIANGLES);
for (Face face : m.faces) {
Vector3f n1 = m.normals.get((int) face.normals.x - 1);
glNormal3f(n1.x, n1.y, n1.z);
Vector3f v1 = m.vertices.get((int) face.vertex.x - 1);
glTexCoord3f(v1.x, v1.y, v1.z);
glVertex3f(v1.x, v1.y, v1.z);
Vector3f v2 = m.vertices.get((int) face.vertex.y - 1);
glTexCoord3f(v2.x, v2.y, v2.z);
glVertex3f(v2.x, v2.y, v2.z);
Vector3f v3 = m.vertices.get((int) face.vertex.z - 1);
glTexCoord3f(v3.x, v3.y, v3.z);
glVertex3f(v3.x, v3.y, v3.z);
}
glEnd();
glEndList();
glPopMatrix();
glLoadIdentity();
Display.update();
Display.sync(60);
}
在哪里
vertex=new Vector3f(); //three indices, not vector
normals= new Vector3f();
使用這段代碼后,我僅獲得渲染對象的一半
嘗試將n個紋理坐標與v個紋理坐標切換。 樹的另一側是否渲染? 一樣嗎 我認為您僅在法線和頂點使用了一半的紋理坐標。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.