0

I have a certain projects which includes many 3d objects from the Glut namespace such as

Glut.glutSolidCone(0.75, 30, 4, 20);

I couldn't find anyway to apply a texture on such objects, only 2d textures worked on 2d objects.

I tried this code, though I believe it's wrong, and it didn't work,

Gl.glPushMatrix();
        Gl.glEnable(Gl.GL_TEXTURE_2D);
        Try.Terrain.LoadGLTextures("Textures/Sitework.Paving - Surfacing.Riverstone.jpg");
        Gl.glTexCoord2d(0, 0);
        Gl.glTexCoord2d(0, 1);
        Gl.glTexCoord2d(1, 1);
        Gl.glTexCoord2d(1, 1);
        Gl.glRotated(90, 1, 0, 0);
        Glut.glutSolidCone(5, 10, 30, 30);
        Gl.glDisable(Gl.GL_TEXTURE_2D);
        Gl.glPopMatrix();

The result was that this 3d object appears with the basic color of the texture applied.

Luna28
  • 527
  • 3
  • 15

2 Answers2

1

glutSolidCone() doesn't contain texture coordinates.

You'll have to generate them yourself.

Community
  • 1
  • 1
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Does that mean that I can't apply any texture without using texture coordinates? – Luna28 May 22 '12 at 21:24
  • 1
    You could use [`glTexGen()`](http://www.opengl.org/sdk/docs/man/xhtml/glTexGen.xml) and friends if you don't want to duplicate `glutSolidCone()`. Or a vertex shader. – genpfault May 22 '12 at 21:50
  • 1
    @LunaAlRawas: Supplying texture coordinate is the only viable thing to do in the long term. There is no kitchen sink algorithm to automatically generate texture coordinates for arbitrary geometries. (There are some very good algorithms, though, but each has its limits). – datenwolf May 22 '12 at 23:49
0

The old function gluCylinder() support texture.

gluCylinder() have two parameters for radius: base and top, so simply set top=0 would generate a cone instead of a cylinder.

GLUquadricObj* quadobj = gluNewQuadric();
gluQuadricTexture(quadobj, GL_TRUE);
glBindTexture(GL_TEXTURE_2D, *your_texture );
gluCylinder(quadobj, 2.0, 0, 3.0, 10, 10);

I'm not sure if there is gluCylinder() in C#.

mewing
  • 1
  • 1