OpenGL을 사용하는 방법을 배우고 있으며 Slick 2D Game 라이브러리에서 몇 가지 실험을 시작하고 있지만 몇 가지 문제가 있습니다.자바 : 드로잉 라인 Slick LWJGL OpenGL
간단한 선을 그려 배열에 저장 한 다음 해당 배열을 반복하여 각 단일 선을 렌더링하려고합니다. 이 메인 클래스입니다 :
ArrayList<Bloco> listaBlocos = new ArrayList<Bloco>();
ArrayList<Linha> listaLinhas = new ArrayList<Linha>();
boolean random = false;
@Override
public void init(GameContainer gc) throws SlickException {
listaBlocos = new ArrayList<Bloco>();
listaLinhas = new ArrayList<Linha>();
}
@Override
public void update(GameContainer gc, int delta) throws SlickException {
Input input = gc.getInput();
if (input.isMousePressed(0))
listaBlocos.add(new Bloco(input.getMouseX() - 5, input.getMouseY() - 5, 10, new Color(0, 255, 0)));
if (input.isMousePressed(1))
listaBlocos.add(new Bloco(input.getMouseX() - 5, input.getMouseY() - 5, 10, new Color(255, 0, 0)));
if (input.isKeyPressed(Input.KEY_A))
if (random == false)
random = true;
else
random = false;
if (input.isKeyPressed(Input.KEY_S))
listaLinhas.add(new Linha(input.getMouseX(), input.getMouseY(), 100, 100));
if (input.isKeyDown(Input.KEY_D))
listaLinhas.get(0).drawLine();
if (!listaBlocos.isEmpty() && random)
for (Bloco b : listaBlocos)
b.moveRandom(delta);
}
public void render(GameContainer gc, Graphics g) throws SlickException {
for (Linha l : listaLinhas)
l.drawLine();
for (Bloco b : listaBlocos)
b.draw(g);
}
그리고 이것은 Linha 클래스입니다 (이 확장 라인) : 렌더링 할 수있는 더 좋은 방법이 있다면
public class Linha extends Line {
public Linha(float x1, float y1, float x2, float y2) {
super(x1, y1, x2, y2);
}
public void drawLine() {
GL11.glColor3f(1.0f, 1.0f, 1.0f);
GL11.glBegin(GL11.GL_LINES);
GL11.glLineWidth(5.0f);
GL11.glVertex2f(getX1(), getY1());
GL11.glVertex2f(getX2(), getY2());
GL11.glEnd();
}
은}
이, 그냥 테스트했다 한 무리의 선이 나에게 말해줘. 문제는 화면에서 선이 깜박이고 항상 선명하지는 않다는 것입니다. 나는 당신이 무슨 일이 일어나고 있는지 볼 수 있도록 문제를 기록했습니다. http://www.youtube.com/watch?v=ymO00yb5NVE