Hey there,
I'm relatively new to OpenGL and I ran into a problem in my recent project. I'm trying to implement a function, which changes the colors of an object when it's clicked on. The logic works fine and the color attributes change, but the scene is not redrawn. Guess I should force a redraw (like glutPostRedisplay), but I'm not sure how it is done in JOGL. Relevant parts of the code: ------------------------------------------------------------------------------------------------------------------------------ public class Main extends Canvas implements GLEventListener { private ArrayList<Shape> setup = new ArrayList<Shape>(); private int charTypes[] = new int[numberOfPlayers]; //0 -> Eskimo, 1 -> Explorer @Override public void display( GLAutoDrawable drawable ) { setUp(charTypes); for(int i = 0; i < setup.size(); i++) { setup.get(i).Draw(gl); } //Checking for choice of characters if(contains(wcoord, setup.get(7), 6) && mousePressed) { charTypes[0] = 0; mouse = null; } else if(contains(wcoord, setup.get(13), 6) && mousePressed) { charTypes[0] = 1; mouse = null; } gl.glClearColor(0.5f, 0.7f, 0.7f, 1f); gl.glFlush(); } public void setUp(int[] alpha) { //Setting shapes setup.add(7, new Hexagon(-0.38f, 0.05625f*2f, 0f, 1.25f, 5f)); //Eskimo setup.add(13, new Hexagon(-0.38f+0.13f, 0.05625f*2f, 0f, 1.25f, 5f)); //Explorer //Coloring shapes setup.get(7).setColor(0.65f/(1+alpha[0]), 0.15f/(1+alpha[0]), 0.15f/(1+alpha[0]), 1f); //Brown setup.get(13).setColor(1f/(2-alpha[0]), 0f/(2-alpha[0]), 0f/(2-alpha[0]), 1f); //Red } } ------------------------------------------------------------------------------------------------------------------------------ public class Hexagon extends Shape { private float[] color = new float[4]; float offsetX; float offsetY; float angle; float scale; float prio; Hexagon(float offsetX, float offsetY, float angle, float scale, float prio) { this.offsetX = offsetX; this.offsetY = offsetY; this.angle = angle; this.scale = scale; this.prio = prio; } public void setColor(float r, float g, float b, float a) { color[0] = r; color[1] = g; color[2] = b; color[3] = a; } public void Draw(GL2 gl) { gl.glPushMatrix(); gl.glTranslatef(offsetX, offsetY, -1.001f-(prio*0.0001f)); gl.glRotatef(angle, 0f, 0.0f, 1.0f); gl.glScalef(scale, scale, scale); gl.glColor4f(color[0], color[1], color[2], color[3]); gl.glBegin(GL2.GL_POLYGON); gl.glVertex3f(0f, 0.05625f, 0); super.sides[0][0] = 0f*scale+offsetX; super.sides[0][1] = (0.05625f)*scale+offsetY; gl.glVertex3f(0.05f, 0.028125f, 0); super.sides[1][0] = 0.05f*scale+offsetX; super.sides[1][1] = (0.028125f)*scale+offsetY; gl.glVertex3f(0.05f, -0.028125f, 0); super.sides[2][0] = (0.05f)*scale+offsetX; super.sides[2][1] = (-0.028125f)*scale+offsetY; gl.glVertex3f(0f, -0.05625f, 0); super.sides[3][0] = (0f)*scale+offsetX; super.sides[3][1] = (-0.05625f)*scale+offsetY; gl.glVertex3f(-0.05f, -0.028125f, 0); super.sides[4][0] = (-0.05f)*scale+offsetX; super.sides[4][1] = (-0.028125f)*scale+offsetY; gl.glVertex3f(-0.05f, 0.028125f, 0); super.sides[5][0] = (-0.05f)*scale+offsetX; super.sides[5][1] = (0.028125f)*scale+offsetY; gl.glEnd(); gl.glPopMatrix(); } } ------------------------------------------------------------------------------------------------------------------------------ Thank you, in advance, for your time and responses. |
Administrator
|
Please provide a SSCCE and use an Animator:
https://jogamp.org/wiki/index.php/Rudimentary_standalone_example_using_the_fixed_pipeline_by_Julien_Gouesse
Julien Gouesse | Personal blog | Website
|
Free forum by Nabble | Edit this page |