【发布时间】:2014-09-06 19:07:09
【问题描述】:
我的程序在生成地形时启动程序一直没有响应。
这是代码。我相信这是 for 循环。
Random Random = new Random();
int numberHeight = Random.nextInt(5);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glColor3f(0.5f,0.5f,1.0f);
int Bottom = Height - 100;
for(int xOffset = 0; xOffset < Width; xOffset = xOffset + 100){
for(int currentHeight = 0; currentHeight < numberHeight; currentHeight = currentHeight++){
GL11.glBegin(GL11.GL_QUADS);
{
GL11.glVertex2f(xOffset,Bottom - currentHeight * 100);
GL11.glVertex2f(xOffset + 100,Bottom - currentHeight * 100);
GL11.glVertex2f(xOffset + 100,Bottom - currentHeight * 100 - 100);
GL11.glVertex2f(xOffset,Bottom - currentHeight * 100 - 100);
}
GL11.glEnd();
if(currentHeight >= numberHeight)break;
}
}
【问题讨论】:
-
你得到什么样的异常?在哪一行?
-
寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及重现它所需的最短代码在问题本身。没有明确的问题陈述的问题对其他读者没有用处。见How to create a Minimal, Complete, and Verifiable example。
-
我认为问题一定是for循环可能使多维数据集超出范围。
标签: java random 2d lwjgl terrain