我需要創建一個正方形的螺旋(相同的大小),完成360度循環後,會改變顏色。例如,我想製作三色螺旋。第一部分可能是藍色的,在第一次循環之後,正方形變成綠色,最後變成紅色。下面是一個可視化的東西我在尋找:如何在OpenGL中創建一個正方形的螺旋? (JAVA)
至今(除JPanel的啄的),我的代碼如下:
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
public class SecondGLEventListener implements GLEventListener {
/**
* Interface to the GLU library.
*/
private GLU glu;
/**
* Take care of initialization here.
*/
public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
glu = new GLU();
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.glViewport(0, 0, 500, 300);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluOrtho2D(0.0, 500.0, 0.0, 300.0);
}
/**
* Take care of drawing here.
*/
public void display(GLAutoDrawable drawable)
{
GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
for (int i=0; i<50; i++)
{
gl.glColor3f(0.0f,0.0f,1.0f);
gl.glPointSize(3);
gl.glBegin(GL.GL_POINTS);
//some code for the spiral thing.
gl.glEnd();
}
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width,
int height) {}
public void displayChanged(GLAutoDrawable drawable,
boolean modeChanged, boolean deviceChanged) {}
}
你有什麼建議如何我可以實現這個?
哦,不!這是作業! – 2012-03-14 19:11:49
是同樣在這裏做作業太:http://stackoverflow.com/questions/26784258/creating-a-multicoloured-spiral-in-opengl-java – gouessej 2014-11-06 18:55:47