View Full Version : Shading pattern for Bars and Cones
01-04-2006, 04:33 AM
I have a cube and a cone structure built in OpenGL. Now I need to apply a gradient (like From Center or Diagonal, etc, as in Windows) to these structures. Can someone please help me on this? I have an image as to show what my structures should look like. http://www.geocities.com/vivekdharm/Bar.bmp
01-04-2006, 05:27 AM
From the posted image it looks like your problem can easily be solved with 1D texturing. A 1D texture can essentially be thought of as a one-dimensional array storing RGB values. You could simply store your intended color gradient in this array and then define a 1D OpenGL texture based on it. When rendering your model, simply assign a 1D texture coordinate to each vertex: 0 is for the left end of the texture, 1 is for the right end. A smooth interpolation ("transition") between the discrete values in your texture array can be easily achieved by setting the OpenGL MIN_FILTER and MAG_FILTER parameters for the texture accordingly.
Hi Joshua. The solution proposed is surely going to help out for sharp edged or fixed vertices structures like cubes and polygons. But we are including structures like Cones and spheres too, where there are no vertices as such. How do I apply the same solution to these shapes?
YOu could try to experiment eith the texture coordinate generation functions (glTexGen with GL_OBJECT_LINEAR) or maybe you have to create texture coordinates yourself - which would probably the best solution with cones or spheres. Then you can easily applay a 1D texture as proposed above.
Danke Kaya. But can you please explain in detail? Since a long time, I am looking for examples in 1D Texture, but not able to find any.
01-05-2006, 01:43 AM
I'm not quite sure I understand your task definition. Even if you generate your own cones and spheres, they are still made up of individual polygons, right? As Kaya said, you could simply generate your own texture coordinates in the range [0;1] for each vertex - it's just that you wouldn't only use 0 or 1 as coordinates. You can do the texture coordinate generation yourself in a preprocessing step, or let OpenGL do it for you. How the texture coordinates have to be generated depends on your actual task. Here is an example where 1D textures are used for creating a cartoon-like effect. In this case, the computed light intensity is used as texture coordinate:
Maybe it would help if you could give us a more detailed description of your problem. What do these gradients depend on? Is there a hypothetical median axis in 3D at the center of your object? Does the gradient depend on image-space coordinates? Your problem also looks a lot like it would be an ideal example application for a shader program.
Bis die Tage,
01-05-2006, 02:10 AM
Wunderschon. That is great. I'll try going through the article. Currently , I am using gluCyclinder function of GLU to draw cones and cylinders. So, no question of having multiple vertices to create them :( But i hope this article would surely be of great help. Let me check it out. Danke sehr viel. Please dont mind my bad German. Still a mediocre in that ;)
01-05-2006, 04:36 AM
I see. I'm afraid you will have to write your own functions for generating the geometry. Any existing function (e.g., from GLU) will not generate the texture coordinates (or activate the appropriate shader programs) for your purpose. However, generating the geometry for simple objects like a cylinder is not difficult. There is currently a similar discussion on creating a sphere geometry in the Maths&Algorithms forum. Moreover, you could simply have a look at the GLU source code.
01-05-2006, 05:09 AM
Yes i guess. Do you know any place where I would find the GLU source code? I went through the openGL library, but it is referring to some Lib file.
01-05-2006, 06:06 AM
Hi! I don't know whether the "official" GLU code is available somewhere, but Mesa 3D most certainly contains an implementation as source code:
They also have a link to SGI's original library:
By the way, an explanation of how to create a cylinder in OpenGL can be found here:
With source code:
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.