为什么可以显示多边形而不能显示点
Why can polygons be displayed but the point cannot
public class SimpleJOGL2 implements GLEventListener {
private float x = 0.5f;
private float y = -0.5f;
public static void main(String[] args) {
Frame frame = new Frame("Simple JOGL Application");
GLCanvas canvas = new GLCanvas();
canvas.addGLEventListener(new SimpleJOGL2());
frame.add(canvas);
frame.setSize(640, 640);
final Animator animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
new Thread(new Runnable() {
public void run() {
animator.stop();
System.exit(0);
}
}).start();
}
});
// Center frame
frame.setLocationRelativeTo(null);
frame.setVisible(true);
animator.start();
}
还有……
public void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
float a[][] = {{x,y},{x,y-0.05f},{x-0.2f,y-0.15f},{x-0.22f, y-0.17f}};
float b[][] = {{x,y},{x,y-0.05f},{x+0.2f,y-0.15f},{x+0.22f, y-0.17f}};
float c[][]= {{x+0.03f,y-0.25f},{x-0.03f,y-0.25f},{x-0.03f,y-0.4f},{x+0.03f,y-0.4f}};
float col[] ={230/255f,84/255f,109/255f};
drawPolygon(gl,a,col);
drawPolygon(gl,b,col);
drawPolygon(gl,c,col);
gl.glLoadIdentity();
gl.glColor3f(0,0,0);
gl.glPointSize(4.0f);
gl.glBegin(GL.GL_POINT);
gl.glVertex2f(x+0.015f, y-0.33f);
gl.glEnd();
gl.glFlush();
}
我想画多边形和点。可以显示多边形,但不能显示点。
public void drawPolygon(GL gl, float a[][], float col[]){
gl.glColor3f(col[0], col[1], col[2]);
gl.glBegin(GL.GL_POLYGON);
gl.glVertex2f(a[0][0], a[0][1]);
gl.glVertex2f(a[1][0], a[1][1]);
gl.glVertex2f(a[2][0], a[2][1]);
gl.glVertex2f(a[3][0], a[3][1]);
gl.glEnd();
}
}
您好,欢迎来到 Whosebug :)
该代码使用了已弃用的 OpenGL 函数,强烈建议除非在特殊情况下不要使用这些函数,我认为这不是你的情况。
当前的 OpenGL 实际上允许三种类型的图元:
GL_TRIANGLES
GL_POINTS
GL_LINES
如果您想了解更多相关信息,可以阅读 wiki。
无论如何,对于初学者来说,最好从一个简单的 Hello Triangle 开始,比如我的 these ones,然后以此为基础进行构建。
所以如果你想显示任何一种多边形,你应该把它分成三角形并将它通过三角形渲染为原始类型
如果您需要进一步的帮助,请不要犹豫,干得好!
public class SimpleJOGL2 implements GLEventListener {
private float x = 0.5f;
private float y = -0.5f;
public static void main(String[] args) {
Frame frame = new Frame("Simple JOGL Application");
GLCanvas canvas = new GLCanvas();
canvas.addGLEventListener(new SimpleJOGL2());
frame.add(canvas);
frame.setSize(640, 640);
final Animator animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
new Thread(new Runnable() {
public void run() {
animator.stop();
System.exit(0);
}
}).start();
}
});
// Center frame
frame.setLocationRelativeTo(null);
frame.setVisible(true);
animator.start();
}
还有……
public void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
float a[][] = {{x,y},{x,y-0.05f},{x-0.2f,y-0.15f},{x-0.22f, y-0.17f}};
float b[][] = {{x,y},{x,y-0.05f},{x+0.2f,y-0.15f},{x+0.22f, y-0.17f}};
float c[][]= {{x+0.03f,y-0.25f},{x-0.03f,y-0.25f},{x-0.03f,y-0.4f},{x+0.03f,y-0.4f}};
float col[] ={230/255f,84/255f,109/255f};
drawPolygon(gl,a,col);
drawPolygon(gl,b,col);
drawPolygon(gl,c,col);
gl.glLoadIdentity();
gl.glColor3f(0,0,0);
gl.glPointSize(4.0f);
gl.glBegin(GL.GL_POINT);
gl.glVertex2f(x+0.015f, y-0.33f);
gl.glEnd();
gl.glFlush();
}
我想画多边形和点。可以显示多边形,但不能显示点。
public void drawPolygon(GL gl, float a[][], float col[]){
gl.glColor3f(col[0], col[1], col[2]);
gl.glBegin(GL.GL_POLYGON);
gl.glVertex2f(a[0][0], a[0][1]);
gl.glVertex2f(a[1][0], a[1][1]);
gl.glVertex2f(a[2][0], a[2][1]);
gl.glVertex2f(a[3][0], a[3][1]);
gl.glEnd();
}
}
您好,欢迎来到 Whosebug :)
该代码使用了已弃用的 OpenGL 函数,强烈建议除非在特殊情况下不要使用这些函数,我认为这不是你的情况。
当前的 OpenGL 实际上允许三种类型的图元:
GL_TRIANGLES
GL_POINTS
GL_LINES
如果您想了解更多相关信息,可以阅读 wiki。
无论如何,对于初学者来说,最好从一个简单的 Hello Triangle 开始,比如我的 these ones,然后以此为基础进行构建。
所以如果你想显示任何一种多边形,你应该把它分成三角形并将它通过三角形渲染为原始类型
如果您需要进一步的帮助,请不要犹豫,干得好!