简体   繁体   English

JOGL无法弄清楚为什么没有出现画线

[英]JOGL cannot figure out why drawn lines are not appearing

I am trying to learn JOGL but first drawing lines (like a border) on my canvas, but I cannot figure out why I the lines are not showing! 我正在尝试学习JOGL,但首先在画布上绘制了线条(如边框)​​,但我无法弄清为什么线条没有显示! I am guess that I haven't set up my viewport correctly. 我猜我没有正确设置视口。

Below are some code snippets: 以下是一些代码片段:

private static final float DISTANCE_FROM_EDGE = 25.0f; 

@Override
public void init(GLAutoDrawable drawable) 
{
  GL2 gl = drawable.getGL().getGL2();
  drawable.setGL(new DebugGL2(gl.getGL2()));

  m_glu = new GLU();

  establishProjectionMatrix(gl , getWidth(), getHeight());

  gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);        
  gl.glEnable(GL2.GL_TEXTURE_2D);
}

@Override
public void reshape(GLAutoDrawable drawable, 
                  int x, 
                  int y, 
                  int width,
                  int height) 
{
  GL2 gl = drawable.getGL().getGL2();
  establishProjectionMatrix(gl , width, height);  
}

public void establishProjectionMatrix(GL2 gl,int width,int height)
{

  gl.glViewport(0, 0, width, height);

  gl.glMatrixMode(GL2.GL_PROJECTION);
  gl.glLoadIdentity();

  m_glu.gluOrtho2D(0,width,height,0);
}

@Override
public void display(GLAutoDrawable drawable) 
{
  update();
  GL2 gl = drawable.getGL().getGL2();
  gl.glClear( GL2.GL_COLOR_BUFFER_BIT );
  gl.glMatrixMode( GL2.GL_MODELVIEW );
  gl.glLoadIdentity();
  drawBoundary(gl);

}

public void drawBoundary(GL2 gl)
{
  gl.glPushMatrix();
  gl.glTranslatef(10.0f, 10.0f, 0.0f); 
  gl.glColor3f(0.0f, 0.1f, 0.0f);
  //Draw left edge
  drawLine(gl, -DISTANCE_FROM_EDGE, -DISTANCE_FROM_EDGE, -DISTANCE_FROM_EDGE,    DISTANCE_FROM_EDGE);
  //Draw top edge
  drawLine(gl, -DISTANCE_FROM_EDGE, DISTANCE_FROM_EDGE, DISTANCE_FROM_EDGE, DISTANCE_FROM_EDGE);
  //Draw right edge
  drawLine(gl, DISTANCE_FROM_EDGE, DISTANCE_FROM_EDGE, DISTANCE_FROM_EDGE, -DISTANCE_FROM_EDGE);
  //Draw bottom edge
  drawLine(gl, DISTANCE_FROM_EDGE, -DISTANCE_FROM_EDGE, -DISTANCE_FROM_EDGE, -DISTANCE_FROM_EDGE);
  gl.glPopMatrix();
}

private void drawLine(GL2 gl, float x1,float y1, float x2, float y2)
{
  gl.glBegin(GL.GL_LINES);
  gl.glVertex2f((x1), (y1));
  gl.glVertex2f((x2), (y2));
  gl.glEnd();
}

Is double-buffering enabled? 是否启用了双缓冲? Try calling drawable.swapBuffers() after rendering. 渲染后尝试调用drawable.swapBuffers()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM