View Full Version : Texture help
10-19-2008, 08:18 PM
I want to wrap textures around a cylinder made with GL_QUAD_STRIP.
The coordinates i have given are cos(theta),y,sin(theta).
How to wrap a texture around it???what are the TexCoord2f() going to be??Please some one help me.I am having prolem with it.Im getting a distorted image.
10-20-2008, 08:20 AM
try theta as s coordinate and y as t.
10-20-2008, 08:51 AM
The side of the cylinder form a square or a rectangle ( this depend of the height/circonference ratio) when you unwrap it. The formula for the u coordinate can be something like this : u = angle/(2*PI) (angle is in radian). For the v coordinate, use v = y/(height of cylinder) for a y axis cylinder => TexCoord2f(u,v). But keep in mind that the texture on the cylinder may appear stretched vertically if the cylinder is tall (ratio of height/circonference > 1), or appear stretched horizontally if the cylinder is small(ratio of height/circonference < 1). So if the ratio of height/circonference != 1, you have two choices, use a rectangle texture if your graphic card support it that meet the ratio above, or use a square texture with coordinates range that meet the ratio (v/u = height/circonference), some part of the square texture are empty. I don't know if there exist some routine in OpenGL or GLU that can scale a texture.
10-20-2008, 02:27 PM
Thank you very much TNT.Hi dont understand the y/height of cylinder.Do u ask me to rename keep v coordinates as 0 and 1.When i use the angle value i am getting the same texture multiple times??
10-20-2008, 02:47 PM
For a square texture, texture coordinates must be between [0 1] for u and v. Here I assume your cylinder start at height y = 0 => y [0 height]. If the origin(0,0,0) is in the center of your cylinder before transformation => y is in the range [-height/2 height/2] then v = ((y/height) + 0.5) to stay the v coordinate between [0 1].
10-20-2008, 02:58 PM
When i use the angle value i am getting the same texture multiple times??
Your angle is defined in degree or radian? If it is in degree, u = angle/360 to stay it in the range [0 1].
10-20-2008, 03:02 PM
Thank you dude now i gt it.But i got another problem.When i move my robot Im getting artifacts on it??How to remove these artifacts??I this is due to postredisplay issue??But i didnt get it bfore.I also want to know how to use multiple textures on it.
10-20-2008, 03:38 PM
But i got another problem.When i move my robot Im getting artifacts on it
This one is hard to resolve without an image to see. You don't need to recalculate texture coordinates each time you move your cylinder, just calculate once. For multitexture I recommend to use glsl. The fixed function way of doing multitexturing is limited in the choice of effect you can use and is not very easy to use.
10-20-2008, 06:31 PM
If your artifact happen when two or more surfaces of your robot overlap, then you suffer Z-fighting. This is due to the depth buffer precision which cannot resolve two or more differents surfaces that are close together. The solutions to avoid this is not simple. You can use polygon offset(not easy), stencil test, or for your robot, cylinder of different radius, a sphere large enough to cover the joint of your cylinders if the artifacts are there.
10-20-2008, 06:40 PM
Thank you very much my friend.It is with display buffers.I used double then flickering stopped.
02-17-2010, 05:07 AM
I have a question please answer me ..
I am trying to do multitexturing on the cylinder(made up of polygons)surface.
I am able to place single texture image on the cylinder surface, but i am not able to place multiple images on it.
Please Help me Sir.
Any answer will appreciated.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.