所以我一直盯着这段代码看似乎有一个半岁了。我是 lwjgl 的新手,但我有一些代码正在运行。问题是我想要一个立方体,它回来时真的很奇怪。从技术上讲,目标只是能够渲染随机数量的立方体,但由于我遇到的错误,我将其减少到只有一个。
我研究过 VBO,但我小组的其他成员都在使用 GL11 - GL13,因为这是最后一部分,我们想坚持下去。
所以,总而言之,我试图只渲染当前的多维数据集,但稍后我可以使用当前设置添加任意数量的多维数据集。任何帮助都会很棒。我已经研究过更改 x、y 和 z。
非常感谢大家的帮助!希望这是主题。
package citygeneratorv0;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
import static org.lwjgl.opengl.GL11.GL_PROJECTION;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glColor3f;
import static org.lwjgl.opengl.GL11.glEnd;
import static org.lwjgl.opengl.GL11.glMatrixMode;
import static org.lwjgl.opengl.GL11.glOrtho;
import static org.lwjgl.opengl.GL11.glVertex3f;
public class CityGeneratorV0 {
private static final List<Box> city = new ArrayList<>(16);
static void generateCity(int numBuildings) {
city.add(new Box());
}
}
public static void main(String args[]) {
try {
Display.setDisplayMode(new DisplayMode(640, 480));
Display.setTitle("Input Demo");
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
Display.destroy();
System.exit(1);
}
int numBuildings = 1;
generateCity(numBuildings);
glMatrixMode(GL_PROJECTION);
glOrtho(0, 640, 480, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
while (!Display.isCloseRequested()) {
glClear(GL_COLOR_BUFFER_BIT);
while (Keyboard.next()) {
if (Keyboard.getEventKey() == Keyboard.KEY_C && Keyboard.getEventKeyState()) {
}
}
if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
Display.destroy();
System.exit(0);
}
for (final Box box : city) {
box.draw();
}
Display.update();
Display.sync(5000);
}
System.out.print(city.size());
Display.destroy();
}
private static class Box {
private float rquad;
Boolean draw() {
GL11.glLoadIdentity(); // Reset The Current Modelview Matrix
GL11.glTranslatef(1.5f, 0.0f, -7.0f); // Move Right 1.5 Units And Into The Screen 6.0
GL11.glRotatef(rquad, 1.0f, 0.0f, 0.0f); // Rotate The Quad On The X axis ( NEW )
glColor3f(0.5f, 0.5f, 1.0f); // Set The Color To Blue One Time Only
glBegin(GL11.GL_QUADS); // Draw A Quad
{
glColor3f(0.0f, 1.0f, 0.0f); // Set The Color To Green
glVertex3f(400, 200, -100); // Top Right Of The Quad (Top)
glVertex3f(300, 200, -100); // Top Left Of The Quad (Top)
glVertex3f(300, 200, -50); // Bottom Left Of The Quad (Top)
glVertex3f(400, 200, -50); // Bottom Right Of The Quad (Top)
glColor3f(1.0f, 0.5f, 0.0f); // Set The Color To Orange
glVertex3f(400, 100, -50); // Top Right Of The Quad (Bottom)
glVertex3f(300, 100, -50); // Top Left Of The Quad (Bottom)
glVertex3f(300, 100, -100); // Bottom Left Of The Quad (Bottom)
glVertex3f(400, 100, -100); // Bottom Right Of The Quad (Bottom)
glColor3f(1.0f, 0.0f, 0.0f); // Set The Color To Red
glVertex3f(400, 200, -50); // Top Right Of The Quad (Front)
glVertex3f(300, 200, -50); // Top Left Of The Quad (Front)
glVertex3f(300, 100, -50); // Bottom Left Of The Quad (Front)
glVertex3f(400, 100, -50); // Bottom Right Of The Quad (Front)
glColor3f(1.0f, 1.0f, 0.0f); // Set The Color To Yellow
glVertex3f(400, 100, -100); // Bottom Left Of The Quad (Back)
glVertex3f(300, 100, -100); // Bottom Right Of The Quad (Back)
glVertex3f(300, 200, -100); // Top Right Of The Quad (Back)
glVertex3f(400, 200, -100); // Top Left Of The Quad (Back)
glColor3f(0.0f, 0.0f, 1.0f); // Set The Color To Blue
glVertex3f(300, 200, -50); // Top Right Of The Quad (Left)
glVertex3f(300, 200, -100); // Top Left Of The Quad (Left)
glVertex3f(300, 100, -100); // Bottom Left Of The Quad (Left)
glVertex3f(300, 100, -50); // Bottom Right Of The Quad (Left)
glColor3f(1.0f, 0.0f, 1.0f); // Set The Color To Violet
glVertex3f(400, 200, -100); // Top Right Of The Quad (Right)
glVertex3f(400, 200, -50); // Top Left Of The Quad (Right)
glVertex3f(400, 100, -50); // Bottom Left Of The Quad (Right)
glVertex3f(400, 100, -100); // Bottom Right Of The Quad (Right)
}
glEnd(); // Done Drawing The Quad
rquad -= 0.15f;
return true;
}
}
}