Skip to main content
GameDev.net gamedev.net
🔒 Locked

swapping between multiple textures....

Started by OpenGL_Guru Jan 11, 2005 at 3:28 PM 6 replies 650+ views
Original Post
OpenGL_Guru
OpenGL_Guru
wondering what the best way to do this is, from an OOP standpoint. when the class is called 2 different textures are loaded from the constructor. this is done by way of a function call into my .bmp reader. in my .bmp reader i do the glGenTextures, then depending on what number i sent in to it from the class it will do 1D, 2D or 3D textures, using various different setups from the texture calls. this also included the Binding of the textures. back in my class i want to do a conditional statement that will determine on which texture gets used. this takes place when i am renderingmy terrain, applying the normals to the terrain and calculating what the texture coordinate for that vertex will be. this is also in a display list. having all of this information what would be the way/best way to swap between the two textures...
heh
_the_phantom_
_the_phantom_
batching.
deal with all texture 1 first, then all texture 2 and so on if needs be
OpenGL_Guru
OpenGL_Guru
if you are building a display list then how can you do all 1 texture then go to 2??? i did not get what you mean by batching. i have a variable declared..well an array as such:

GLuint color_ramps[2];

i load 2 different textures(.bmp's) in this array. now i just need to access which one. if i do this in the display list.. only the last texture i loaded inthe color-ramps array will be used.
heh
Jan-Lieuwe
Jan-Lieuwe
I think _the_phantom_ tries to tell you that texture switches are expensive. Try to draw as many geometry as you can between the texture switching.
_the_phantom_
_the_phantom_
right, just checked and it doesnt say anything about not being allowed to bind textures in a display list, so what you'd do is;

- start the display list
- bind the first texture
- do whatever you do to make the display list data
- bind 2nd texture
- make data for that section of the display list
- finish display list

That should work fine.

'batching' is just the act of outputting all commands which use one state and then changing any states required then outputting all commands which use the new state and so on. (state changes being things such as texture bind, materical changes, shader binds etc).
This is done because, as Jan-Lieuwe says, texture switches are expensive.
However, in this case it also makes sense todo it this way as you are only ever accessing one texture at a time.
OpenGL_Guru
OpenGL_Guru
well the most i can draw without swapping textures would be one vertex, since the next vertex could be below or above land. the data size is about 2000 X 1500 X 3 and is a meidum size resolution of the whole world. i am trying to color map it right according to what is realistic. like around 0 or a little above would be the beach, then you have lowlands, darker green for higher points and white for snowtops. below 0 would be all shades of blue. i created this texture in paint so i am using that to probe my colors. maybe i wont have to swap textures. lets say i can have a conditional statement by saying,

if(current_height >= 0)
draw the upper portion of the 1D texture, that is light green to white
else if(current_height < 0)
draw the bottom portion of the 1D texture, that is light blue to dark blue

since my texture goes from 0.0 to 1.0, i have to find a way to get the coordinate for the texture without blending.. anyway what do you think of this idea? how could i get a range of colors of the texture from this formula that i am already using?? .. which is:

glTexCoord1f((terrainW[index].z - getMinW())/(getMaxW() - getMinW()));

this spans the whole texture from 0.0 to 1.0.
if the height is >=0 i would only want lets say the colors from 0.55 to 1.0
< 0 i would want the colors of the texture from 0.45 down to 0.

if someone is willing to take a screenie i make and post it here i can email it to you -- then you can see more of what i am looking for..
heh
kburkhart84
kburkhart84
I don't understand exactly how you are drawing the terrain. Are you using a grayscale texture or what. How is the texture being stored? What si the 1d texture for exactly? Why not use a 2d texture? I think that terrain should be stored either as a group of indexed triangles, like a model, or an array of floats saying the height at that point. The second is easier, but more limited in that you can't have the terrain go over itself rather there can only be one height per position. Are you doing multitexturing on the terrain? I don't think you can draw a terrain by using texture coords. I see that the 1d texture is for just the color. Couldn't you just set the color with OpenGL. The shading between colors is done automatically with OpenGL anyway. Also, you could use a grass texture or something like that.


OpenGL_Guru
OpenGL_Guru
i am drawing the terrain using GL_TRIANGLE_STRIPS, actual data(numbers) that i have stored, i did not store it from a .raw file or anything. its about 6 million vertices.. in actuality its terrain of the WHOLE world, each point is a x, y and height value associated with it. you can get the data off of the noaa site. this is the display list code i have also assigning the texture coordinate values...i store my values in a 1D array when the data file is passed into the constructor. thats what the indexing is for just in case you didnt know. if i just set the Color using openGL using glColor3f() is what i am assuming that you mean, there is some shading but not interpolation/blending between colors. you would still get sudden lines from one color to the next. when drawing a 2D square or a 3D cube it doesnt matter as much and is really not noticeable but when you have millions of vertices you need a good blending effect. this is where a 1D texture comes in. i created the 1D texture in paint, 16 texels in width and obviously 1 texel in height. each texel is a different color or a slight shade of a color. in my loop i see what the height value is, subtract the minimum height of the whole data set then divide by the max height - min height, which will give me an exact value on the texture that matches that height. essentially it converts my height values between 0 and 1 to match up with my 1D texture, which goes from 0.0 to 1.0. my problem is is that i DON't want blending right around 0 because where the heights are 0 are less than 0 i might get some greens which really would look very good. so i need to have a cut off right around that point so that there is no blending. i could use 2 textures but that seems to be harder doing a conditional statement switching between textures like that.

void Cgeoids::display_list_world(GLuint &world_list){ int count = 0; int index; world_list = glGenLists(1); glNewList(world_list, GL_COMPILE);  for(int j = 0; j < y_size-1; j++)   {    glBegin(GL_TRIANGLE_STRIP);     for(int i = 0; i < x_size; i++)      {       index = j*x_size+i;       if(flag != 0)       {        glNormal3f(normalsW[index].x, normalsW[index].y, normalsW[index].z);        glTexCoord1f((terrainW[index].z - getMinW())/(getMaxW() - getMinW()));       }        glVertex3f(terrainW[index].x, terrainW[index].y, terrainW[index].z);             index += x_size;            if(flag != 0)	{	 glNormal3f(normalsW[index].x, normalsW[index].y, normalsW[index].z);	 glTexCoord1f((terrainW[index].z - getMinW())/(getMaxW() - getMinW()));	}     	glVertex3f(terrainW[index].x, terrainW[index].y, terrainW[index].z);    }    glEnd();   }  glEndList();} 
heh

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.