Jump to content
  • Advertisement
Sign in to follow this  
cockney

What am i doing wrong?

This topic is 4966 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

k I need to apply a texture to an object created from reading points from file (data file is a text containing xyz coordinates). Whatever i do seems not to work, the closest thing to what I'm afetr is , using the GL_POLYGON function. With that function the whole object appears in the texture's color but the texture itself!!! anyway here is the code can some tell me what am I doing wrong?

public override void glDraw() 
{									GL.glClear(GL.GL_COLOR_BUFFER_BIT | L.GL_DEPTH_BUFFER_BIT);
GL.glLoadIdentity ();
GL.glEnable(GL.GL_BLEND);
GL.glBindTexture(GL.GL_TEXTURE_2D, Textures[0]);
GL.glCallList(Textures_dispList[0]);
GL.glMatrixMode(GL.GL_MODELVIEW);
GL.glTranslatef(cx, cy, cz);
GL.glRotatef(xrot, 1, 0, 0);
GL.glRotatef(yrot, 0, 1, 0);
GL.glRotatef(zrot, 0, 0, 1);
xrot += xspeed;
yrot += yspeed;
zrot += zspeed;
float tx, ty, tz;
Vertex q;
GL.glPolygonMode(GL.GL_FRONT, GL.GL_FILL);

GL.glBegin(GL.GL_POLYGON);
for(int i = 0; i < morph1.verts; i++) 
{ if(morph)
{q = Calculate(i);}
else{	q.x = q.y = q.z = 0;}
helper.points.x -= q.x;
helper.points.y -= q.y;
helper.points.z -= q.z;
tx = helper.points.x;
ty = helper.points.y;						tz = helper.points.z;
GL.glColor3f(30.0f, 0.0f, 10.0f);
GL.glTexCoord2f(tx,ty );
GL.glVertex3f(tx, ty, tz);
}
GL.glEnd();		
GL.glPolygonMode(GL.GL_BACK, GL.GL_LINE);
}






so what do you think ? thx [Edited by - cockney on December 4, 2004 12:20:25 AM]

Share this post


Link to post
Share on other sites
Advertisement
two things:

1) make sure you are enabling texturing: glEnable(GL_TEXTURE_2D);
2) You are supplying the same texture coordinates (0,0) for each vertex, this will map the first pixel in the texture to each of the vertices (thus making the object the same colour as the first pixel).

Share this post


Link to post
Share on other sites
I know so little it's scary, BUT... have you checked that the order in which your vertices are specified, is correct? Can you render your object without texturing and it shows up OK?

Share this post


Link to post
Share on other sites
thx for your comments.

I have enabled texturing with glEnable(GL_TEXTURE_2D); and changed the texture coordinates:

GL.glTexCoord2f(tx,ty );

The thing is that the texture shows like in "slices" when the object is rotated (for some odd reason). How can i make it apply uniformally to the object (while in rotation)?

thx

[Edited by - cockney on December 1, 2004 1:47:42 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It looks like you are using the same coordinates for texture and vertex. If those values (tx, ty) arent 0f to 1f, then you will get (I think) a repeating texture effect, which on a >4 vertex polygon probably looks pretty weird. If that's the case, convert tx, ty to a fraction of the total x, y range like,

float txFraction = (tx - MinX) / (MaxX - MinX);

and use those values for the texture coordinates.

Share this post


Link to post
Share on other sites
I know that the issue relies somewhere on the texture coordinates. the problem is that whatever I have tried it did nto work.

Tried the last suqqestion as well but did not work, for some odd reason I don't get any texture on my polygon just lines.

any other ideas guys?

cheers

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!