Hi,
I am trying to apply a texture to a quad, obviously I fail, I browse the forum but I dont understand the procedure on getting this to work, so here is what I got
Main sketch
Code:// tutorial from
// http://nehe.gamedev.net/
// under OpenGL Tutorials section
import processing.opengl.PGraphicsOpenGL;
import javax.media.opengl.GL;
import javax.media.opengl.glu.GLU;
GLU glu;
PGraphicsOpenGL pgl;
GL gl;
PImage boxTexture;
Cube cube;
void setup() {
size(320, 240, OPENGL);
boxTexture = loadImage("box-up.jpg");
glu = new GLU();
pgl = (PGraphicsOpenGL) g;
cube = new Cube(boxTexture);
}
void draw() {
background(0);
gl = pgl.beginGL();
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
// calc aspect ratio of the window
glu.gluPerspective(45.0f, width / height, 0.1f, 100.0f);
gl.glMatrixMode(GL.GL_MODELVIEW);
// clear the screen and the depth buffer
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
drawGLScene();
pgl.endGL();
}
void drawGLScene() {
gl.glLoadIdentity();
gl.glTranslatef(1.5f, 0.0f, -8.0f);
cube.setGL(gl);
cube.update();
cube.display();
}
Cube class
Code:class Cube {
GL gl;
PImage boxTexture;
int texSize;
int[] tex = new int[1];
float rquad;
Cube(PImage _texture) {
boxTexture = _texture;
texSize = boxTexture.width;
//println(tex);
}
void setGL(GL _gl) {
gl = _gl;
}
void update() {
// rotate square
rquad += 0.5f;
gl.glRotatef(rquad, 1.0f, 0.0f, 0.0f);
gl.glRotatef(rquad, 0.0f, 1.0f, 0.0f);
gl.glRotatef(rquad, 0.0f, 0.0f, 1.0f);
}
void display() {
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glGenTextures(1, tex, 0);
gl.glBindTexture(GL.GL_TEXTURE_2D, tex[0]);
gl.glTexImage2D(GL.GL_TEXTURE_2D,
0,
3,
boxTexture.width,
boxTexture.height,
0,
GL.GL_RGB,
GL.GL_UNSIGNED_BYTE,
null);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glBegin(GL.GL_QUADS);
// top face
gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 1.0f);
gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f, 1.0f);
gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f( 1.0f, 1.0f, 1.0f);
gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f, 1.0f, 1.0f);
gl.glEnd();
}
}
To be honest I just trow an arrow there, and hope for the best, I just dont get this 3 methods
glGenTextures
glBindTexture
glTexImage2DThanks
rS