我在编写我的一门课程时遇到了错误。
我的进口是,
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.glClear;
import static org.lwjgl.opengl.GL11.glLoadIdentity;
import static org.lwjgl.opengl.GL11.glMatrixMode;
import static org.lwjgl.opengl.GL11.glOrtho;
import java.util.Random;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
public class InputDemo{
public InputDemo(){
int height = 720;
int width = 1280;
try {
Display.setDisplayMode(new DisplayMode(1280, 720));
Display.setTitle("Input Demonstration");
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
//Initialization code OpenGL
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1280.0, 720.0, 0.0, 1.0, -1.0);
glMatrixMode(GL_MODELVIEW);
while(!Display.isCloseRequested()) {
//Render (Quads are X, Y (Across, Up + Down))
glClear(GL_COLOR_BUFFER_BIT);
if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
{
Display.destroy();
System.exit(0);
}
int dx = Mouse.getDX();
int dy = -Mouse.getDY();
System.out.println(dx + ", " + dy);
Display.update();
Display.sync(60);
}
Display.destroy();
}
private static class Box{
public int x, y;
public boolean selected = false;
private float colorRed, colorBlue, colorGreen;
Box(int x, int y)
{
this.x = x;
this.y = y;
Random randomGenerator = new Random();
colorRed = randomGenerator.nextFloat();
colorBlue = randomGenerator.nextFloat();
colorGreen = randomGenerator.nextFloat();
}
boolean inBounds(int mousex, int mousey)
{
if(mousex > x && mousex < x + 50 && mousey > y && < y + 50)
return true;
else
return false;
}
void update(int dx, int dy)
{
x += dx;
y += dy;
}
void randomizeColors()
{
Random randomGenerator = new Random();
colorRed = randomGenerator.nextFloat();
colorBlue = randomGenerator.nextFloat();
colorGreen = randomGenerator.nextFloat();
}
void draw()
{
glBegin(GL_QUADS);
glVertex2f(x, y);
glVertex2f(x + 50, y);
glVertex2f(x + 50, y + 50);
glVertex2f(x, y + 50);
glEnd();
}
}
/**
* @param args
*/
public static void main(String[] args) {
new InputDemo();
}
}
错误是 'class' 的语法错误,@ expected' 以及 'Insert '}' to complete block'
另外,你能看到 draw() 的错误吗,因为我不能,但 glBegin 不起作用,因为 'GL_QUADS 不是变量,但我找不到我在哪里使用它作为变量...... '