token error : pgl
in
Programming Questions
•
3 years ago
import processing.opengl.PGraphicsOpenGL;
import javax.media.opengl.GL;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
import com.sun.opengl.util.texture.Texture;
import com.sun.opengl.util.texture.TextureIO;
import peasy.PeasyCam; //peasy camera control
void setup() {
size(screenWidth, screenHeight, OPENGL );
frameRate(24);
planet.draw();
}
class Planet{
PGraphicsOpenGL pgl;
GL gl;
GLU glu;
GLUquadric mysphere;
Texture earth;
PeasyCam cam;
float rotateearth = 0;
float r;
pgl = (PGraphicsOpenGL) g;
gl = pgl.gl;
glu = pgl.glu;
mysphere = glu.gluNewQuadric();
glu.gluQuadricDrawStyle(mysphere, glu.GLU_FILL);
glu.gluQuadricNormals(mysphere, glu.GLU_NONE);
glu.gluQuadricTexture(mysphere, true);
float fov = PI/3.0;
float cameraZ = (height/2.0) / tan(fov/2.0);
Planet(String fileName, float radius){
perspective(fov, float(width)/float(height), cameraZ/10.0, cameraZ*32.0);
cam = new PeasyCam(this, width);
cam.setResetOnDoubleClick(false);
cam.setMinimumDistance(width/14);
cam.setMaximumDistance(width*10);
cam.rotateZ(radians(-90));
cam.rotateX(radians(105));
r = radius
try {
earth = TextureIO.newTexture(new File(dataPath(println fileName)), true);
/* http://apod.nasa.gov/apod/image/0203/earthtruecolor_nasa_big.jpg */
}
catch (IOException e) {
javax.swing.JOptionPane.showMessageDialog(this, e);
}
}
void draw() {
background(0);
pgl.beginGL();
gl.glPushMatrix();
gl.glRotatef(degrees(rotateearth),0.0,0.0,1.0);
gl.glColor3f(1,1,1);
earth.enable();
earth.bind();
glu.gluSphere(mysphere, r/PI, 40, 40);
earth.disable();
gl.glPopMatrix();
pgl.endGL();
if (rotateearth < 360) {
rotateearth = rotateearth + .0005;
}
else {
rotateearth = 0;
}
println(frameRate);
}
Anyone that can enlight me the problem to this code?
was there a problem placing the openGL varibles inside the class?
and furthermore, for the filename part, is it do-able in this current method?
whereby I use a string to get the input(eg. venus.jpg) and place it under the
earth = TextureIO.newTexture(new File(dataPath(println fileName)) part.
Thanks in advance for any replies~!
import javax.media.opengl.GL;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
import com.sun.opengl.util.texture.Texture;
import com.sun.opengl.util.texture.TextureIO;
import peasy.PeasyCam; //peasy camera control
void setup() {
size(screenWidth, screenHeight, OPENGL );
frameRate(24);
planet.draw();
}
class Planet{
PGraphicsOpenGL pgl;
GL gl;
GLU glu;
GLUquadric mysphere;
Texture earth;
PeasyCam cam;
float rotateearth = 0;
float r;
pgl = (PGraphicsOpenGL) g;
gl = pgl.gl;
glu = pgl.glu;
mysphere = glu.gluNewQuadric();
glu.gluQuadricDrawStyle(mysphere, glu.GLU_FILL);
glu.gluQuadricNormals(mysphere, glu.GLU_NONE);
glu.gluQuadricTexture(mysphere, true);
float fov = PI/3.0;
float cameraZ = (height/2.0) / tan(fov/2.0);
Planet(String fileName, float radius){
perspective(fov, float(width)/float(height), cameraZ/10.0, cameraZ*32.0);
cam = new PeasyCam(this, width);
cam.setResetOnDoubleClick(false);
cam.setMinimumDistance(width/14);
cam.setMaximumDistance(width*10);
cam.rotateZ(radians(-90));
cam.rotateX(radians(105));
r = radius
try {
earth = TextureIO.newTexture(new File(dataPath(println fileName)), true);
/* http://apod.nasa.gov/apod/image/0203/earthtruecolor_nasa_big.jpg */
}
catch (IOException e) {
javax.swing.JOptionPane.showMessageDialog(this, e);
}
}
void draw() {
background(0);
pgl.beginGL();
gl.glPushMatrix();
gl.glRotatef(degrees(rotateearth),0.0,0.0,1.0);
gl.glColor3f(1,1,1);
earth.enable();
earth.bind();
glu.gluSphere(mysphere, r/PI, 40, 40);
earth.disable();
gl.glPopMatrix();
pgl.endGL();
if (rotateearth < 360) {
rotateearth = rotateearth + .0005;
}
else {
rotateearth = 0;
}
println(frameRate);
}
Anyone that can enlight me the problem to this code?
was there a problem placing the openGL varibles inside the class?
and furthermore, for the filename part, is it do-able in this current method?
whereby I use a string to get the input(eg. venus.jpg) and place it under the
earth = TextureIO.newTexture(new File(dataPath(println fileName)) part.
Thanks in advance for any replies~!
1