所以,我有我的引擎一個問題,即我對現在的工作:OpenGL的移動四邊形
的一點是,它應該產生其中的16×16的平臺。
這是創建立方體代碼:
private void render(){
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT|GL11.GL_DEPTH_BUFFER_BIT);
for(int x=0; x<16; x++){
for(int z=0; z<16; z++) {
b.renderBlock(x, 0, z, texture);
}
}
glMatrixMode(GL_MODELVIEW);
GL11.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
GL11.glEnable(GL_CULL_FACE);
GL11.glLoadIdentity();
}
這應該呈現塊16×16平臺
Block.java(b.renderblock)
package net.themorfeus.awesum.adventure.game;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
public class Block {
private float rquad = 0f;
public void renderBlock(int posx, int posy, int posz, Texture t) {
t.bind();
//GL11.glLoadIdentity(); // Reset The Current Modelview Matrix
GL11.glTranslatef(posx,posy,posz); // Move Right 1.5 Units And Into The Screen 6.0
GL11.glRotatef(rquad,0.0f,0.0f,1.0f); // Rotate The Quad On The X axis (NEW)
GL11.glColor3f(1.0f,1.0f,1.0f); // Set The Color To Blue One Time Only
GL11.glBegin(GL11.GL_QUADS); // Draw A Quad
//GL11.glColor3f(0.5f, 0.4f, 0.4f); // Set The Color To Green
GL11.glTexCoord2f(0,0);
GL11.glVertex3f(1f, 1f,-1f); // Top Right Of The Quad (Top)
GL11.glTexCoord2f(1,0);
GL11.glVertex3f(-1f, 1f,-1f); // Top Left Of The Quad (Top)
GL11.glTexCoord2f(1,1);
GL11.glVertex3f(-1f, 1f, 1f); // Bottom Left Of The Quad (Top)
GL11.glTexCoord2f(0,1);
GL11.glVertex3f(1f, 1f, 1f); // Bottom Right Of The Quad (Top)
//GL11.glColor3f(1.2f,0.5f,0.9f); // Set The Color To Orange
GL11.glTexCoord2f(0,0);
GL11.glVertex3f(1f,-1f, 1f); // Top Right Of The Quad (Bottom)
GL11.glTexCoord2f(0,1);
GL11.glVertex3f(-1f,-1f, 1f); // Top Left Of The Quad (Bottom)
GL11.glTexCoord2f(1,1);
GL11.glVertex3f(-1f,-1f,-1f); // Bottom Left Of The Quad (Bottom)
GL11.glTexCoord2f(1,0);
GL11.glVertex3f(1f,-1f,-1f); // Bottom Right Of The Quad (Bottom)
//GL11.glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
GL11.glTexCoord2f(0,0);
GL11.glVertex3f(1f, 1f, 1f); // Top Right Of The Quad (Front)
GL11.glTexCoord2f(1,0);
GL11.glVertex3f(-1f, 1f, 1f); // Top Left Of The Quad (Front)
GL11.glTexCoord2f(1,1);
GL11.glVertex3f(-1f,-1f, 1f); // Bottom Left Of The Quad (Front)
GL11.glTexCoord2f(0,1);
GL11.glVertex3f(1f,-1f, 1f); // Bottom Right Of The Quad (Front)
//GL11.glColor3f(1f,0.5f,0.0f); // Set The Color To Yellow
GL11.glTexCoord2f(0,0);
GL11.glVertex3f(1f,-1f,-1f); // Bottom Left Of The Quad (Back)
GL11.glTexCoord2f(1,0);
GL11.glVertex3f(-1f,-1f,-1f); // Bottom Right Of The Quad (Back)
GL11.glTexCoord2f(1,1);
GL11.glVertex3f(-1f, 1f,-1f); // Top Right Of The Quad (Back)
GL11.glTexCoord2f(0,1);
GL11.glVertex3f(1f, 1f,-1f); // Top Left Of The Quad (Back)
//GL11.glColor3f(0.0f,0.0f,0.3f); // Set The Color To Blue
GL11.glTexCoord2f(0,1);
GL11.glVertex3f(-1f, 1f, 1f); // Top Right Of The Quad (Left)
GL11.glTexCoord2f(1,1);
GL11.glVertex3f(-1f, 1f,-1f); // Top Left Of The Quad (Left)
GL11.glTexCoord2f(1,0);
GL11.glVertex3f(-1f,-1f,-1f); // Bottom Left Of The Quad (Left)
GL11.glTexCoord2f(0,0);
GL11.glVertex3f(-1f,-1f, 1f); // Bottom Right Of The Quad (Left)
//GL11.glColor3f(0.5f,0.0f,0.5f); // Set The Color To Violet
GL11.glTexCoord2f(0,0);
GL11.glVertex3f(1f, 1f,-1f); // Top Right Of The Quad (Right)
GL11.glTexCoord2f(1,0);
GL11.glVertex3f(1f, 1f, 1f); // Top Left Of The Quad (Right)
GL11.glTexCoord2f(1,1);
GL11.glVertex3f(1f,-1f, 1f); // Bottom Left Of The Quad (Right)
GL11.glTexCoord2f(0,1);
GL11.glVertex3f(1f,-1f,-1f); // Bottom Right Of The Quad (Right)
GL11.glEnd();
//rquad+=0.0000001f;
}
}
它基本上呈現塊四邊形。
只是一個建議:你應該真的擺脫那個即時模式代碼('glBegin()... glEnd()')。所有這些函數調用開銷在本地代碼中已經足夠糟糕,跨越JNI邊界並沒有讓它變得更好。使用頂點數組和頂點緩衝區對象。 – datenwolf 2012-03-31 15:27:49