Jump to content
  • Advertisement
Sign in to follow this  

Texturing a Cube using glTexGen

This topic is 3821 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!