Sign in to follow this  

Texturing a Cube using glTexGen

This topic is 3659 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, i want to texture a cube using the automatic texture coordinate generation. I have a method drawCube which draws a cube. When i set the parameters for the coordinate generation like this: float[] s = {0.1f,0.0f,0.0f,0f}; float[] t = {0.0f,0.1f,0f,0.0f}; gl.glTexGenfv(GL.GL_S, GL.GL_OBJECT_PLANE, s,0); gl.glTexGenfv(GL.GL_T, GL.GL_OBJECT_PLANE, t,0); drawCube(); It works for the front side. Do i have to change this parameters for every side of the cube or is there a more easy way? public void drawCube() { float w = 10; float d = 10; float h = 10; float[] v1 = new float[]{w, h, 0}; float[] v2 = new float[]{0, h, 0}; float[] v3 = new float[]{0, 0, 0}; float[] v4 = new float[]{w, 0, 0}; float[] v5 = new float[]{w, h, -d}; float[] v6 = new float[]{0, h, -d}; float[] v7 = new float[]{0, 0, -d}; float[] v8 = new float[]{w, 0, -d}; gl.glBegin(GL.GL_QUADS); gl.glNormal3f(0,0,1); gl.glVertex3fv(v1,0); gl.glVertex3fv(v2,0); gl.glVertex3fv(v3,0); gl.glVertex3fv(v4,0); gl.glNormal3f(1,0,0); gl.glVertex3fv(v5,0); gl.glVertex3fv(v1,0); gl.glVertex3fv(v4,0); gl.glVertex3fv(v8,0); gl.glNormal3f(-1,0,0); gl.glVertex3fv(v2,0); gl.glVertex3fv(v6,0); gl.glVertex3fv(v7,0); gl.glVertex3fv(v3,0); gl.glNormal3f(0,1,0); gl.glVertex3fv(v5,0); gl.glVertex3fv(v6,0); gl.glVertex3fv(v2,0); gl.glVertex3fv(v1,0); gl.glNormal3f(0,-1,0); gl.glVertex3fv(v7,0); gl.glVertex3fv(v8,0); gl.glVertex3fv(v4,0); gl.glVertex3fv(v3,0); gl.glNormal3f(0,0,-1); gl.glVertex3fv(v6,0); gl.glVertex3fv(v5,0); gl.glVertex3fv(v8,0); gl.glVertex3fv(v7,0); gl.glEnd(); }

Share this post


Link to post
Share on other sites
I don't know if you are doing this as a execise or not.
If it's for execise, yes, you have to change the plane equations
These two
float[] s = {0.1f,0.0f,0.0f,0f};
float[] t = {0.0f,0.1f,0f,0.0f};

To be realistic, assign static texture coordinates for all your 3d models.

Share this post


Link to post
Share on other sites

This topic is 3659 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this