Archived

This topic is now archived and is closed to further replies.

OpenGL_Guru

Creating your Own Textures - 1D

Recommended Posts

i am looking to create my own 1D texture. i will use this to color my terrain that i have up and running. i want a nice shade of colors which is why i want to go this route. i am used to just loading in 2D textures so i would like to know if anyone could be of some help in created a 1D texture and applying it to the surface. i want to base the color according to the height in meters of the terrain and any given vertex. this is what i have so far.. GLubyte myTexture[256][3]; GLfloat colors[][3] = { {0.357, 0.268, 0.137}, {0, .3, .7}, {0, 0 , 1} }; the first color is land, like a brownish color, the 2nd color is a bluish tone and the last color is dark dark blue for the water which would represent the lowest height values for those vertices. glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, myTexture); -- this tells openGL how to set up the texture?? im assuming. now lets say i have my loop like such.... for (int i = 0; i< num_verts; i++) { glVertex(......) } lets say within this loop i get the depth of every vertex and depending on the depth will be what color i assign the texture coordinate that matches the current vertex. so could anyone give me a hand on where things need to go to set this up? thanks so much in advance!!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Is this really a 1D texture you are after? It sounds to me like you just need to look up the vertex colours from a lookup table. I think a 1D texture is for texturing a 1D object, i.e. a line.

You need to setup a lookup table for your colour array, or fit it to an equation (for separate RGB). Then use your vertex height to lookup or calculate the colour for that vertex.

Share this post


Link to post
Share on other sites
yes a 1D texture is what i am after to a smooth transition between colors. obviously just doing basic glColor3f calls arent going to be enough as the smoothing of colors is usually too blocky.

i can set colors depending on the height of a vertex but what about the colors in between vertices? GL_SMOOTH does do some smoothing but not good enough..with a 1D texture OGL interpolates the tex coords assoiated with the vertices of the terrain, so when you apply color to your texture coordinates they are interpolated...

maybe someone can give me an idea or at least tell me how to create your own texture and assign colors to a texture that i have created?

Share this post


Link to post
Share on other sites
I dont think the glcolor3f() is going to be blocky. Colors are interpolated same as texures. Since in a terrain adjacent polygons share verticies the collor from one polgon is going to transition smoothly into the other because at verticies adjacent polygons share the same color since they sahre same vetecies. Hope this makes sence. This is pretty much how cougard shading works except the color of the vertecies on the terrain is determined based on height.

Share this post


Link to post
Share on other sites
i guess blocky was maybe the wrong word.. i should have said a smooth neat crisp transition between land and water for example. they might be adjacent but if one vertex is much lower in 3D space than another vertex the colors are not going to do what i am looking for. is there anything on site to help with creating a 1D texture and assigning colors to the coordinates? thanks.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
omg, if you only have 3 colors in your lookup table, than you are only gonna have 3 colors for your vertices & this won''t look too good at all. Perhaps you need to write an interpolator that takes the height a vertex & then blends the colors in the lookup table that bound that height, for example... so you are halfway between the blue tone & the water color... than you probably want to do:

GLfloat VertexColor[3];
VertexColor[0] = ( colors[1][0] + colors[2][0] ) / 2.0f;
VertexColor[1] = ( colors[1][1] + colors[2][1] ) / 2.0f;
VertexColor[2] = ( colors[1][2] + colors[2][2] ) / 2.0f;

ok... maybe not EXACTLY that, but something like that. You will of course have to abstract it more to handle the whole range between the two colors, not just the midpoint.

Share this post


Link to post
Share on other sites