Rotating a quad in opengl HELP!
in
Core Library Questions
•
1 year ago
Hey all, I have some code that I've been trying to make. It draws a circle on a quad and then tries to rotate it- I took some solutions from online but for some reason this stupid thing isn't rotating! Nothing changes... anyway here's my code. Can anyone take a quick gander and help out? You experts can probably spot the problem just by looking at the code...
- import processing.opengl.*;
- import javax.media.opengl.*;
- import javax.media.opengl.glu.*; //...
- import com.sun.opengl.util.texture.*;
- Texture tex;
- int x = 251, y = 98;
- ArrayList ps;
- PGraphicsOpenGL pgl;
- GL gl;
- GLU glu = new GLU();
- void setup()
- {
- size(800,600, OPENGL);
- try { tex=TextureIO.newTexture(new File(dataPath("ring1.png")),true); }
- catch(Exception e) { println(e); }
- ps = new ArrayList();
- pgl = (PGraphicsOpenGL) g;
- colorMode(RGB,1.0);
- }
- void draw()
- {
- background(0);
- gl = pgl.beginGL();
- tex.bind();
- tex.enable();
- gl.glMatrixMode(GL.GL_TEXTURE);
- gl.glLoadIdentity();
- gl.glTranslatef(0.5,0.5,0.0);
- gl.glRotatef(PI/3,0.0,0.0,1.0);
- gl.glTranslatef(-0.5,-0.5,0.0);
- gl.glMatrixMode(GL.GL_MODELVIEW);
- gl.glBegin(GL.GL_QUADS);
- for( int i = 0 ; i < ps.size() ; ++i )
- {
- Particle p = (Particle) ps.get(i);
- p.execute(gl);
- if( !p.update() )
- {ps.remove(i);}
- }
- gl.glColor4f( 0, 1, 1, .1);
- gl.glNormal3f( 0.0f, 0.0f, 1.0f);
- gl.glTexCoord2i(0, 0); gl.glVertex2f(0, 0);
- gl.glTexCoord2i(1, 0); gl.glVertex2f(500, 0);
- gl.glTexCoord2i(1, 1); gl.glVertex2f(500, 250);
- gl.glTexCoord2i(0, 1); gl.glVertex2f(0, 250);
- gl.glEnd();
- tex.disable();
- pgl.endGL();
- }
- void mouseClicked()
- {
- ps.add(new Particle(width/2, height/2, 0, tex, gl));
- }
- class Particle
- {
- PVector d_pos;
- Texture d_tex;
- int d_size;
- GL d_gl;
- color d_col;
- float d_fade;
- Particle( float x, float y, float z, Texture tex, GL gl)
- {
- d_pos = new PVector( x, y , z);
- d_size = 100;
- d_tex = tex;
- d_col = color(1,1,.5);
- d_fade = 1;
- d_gl = gl;
- }
- void execute(GL gl)
- {
- gl.glColor4f( red(d_col), green(d_col), blue(d_col), d_fade);
- gl.glNormal3f( 0.0f, 0.0f, 1.0f);
- gl.glTexCoord2f(0, 0); gl.glVertex3f(d_pos.x-d_size/2, d_pos.y-d_size/2,0);
- gl.glTexCoord2f(1, 0); gl.glVertex3f(d_pos.x + d_size/2 , d_pos.y - d_size/2,0);
- gl.glTexCoord2f(1, 1); gl.glVertex3f(d_pos.x + d_size/2, d_pos.y + d_size/2,0);
- gl.glTexCoord2f(0, 1); gl.glVertex3f(d_pos.x - d_size/2, d_pos.y + d_size/2,0);
- }
- boolean update()
- {
- d_fade *= .98;
- d_pos.y-=1;
- if( d_fade > 0.01 )
- return true;
- return false;
- }
- }
1