Archived

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

MARS_999

Terrain engine question on textures selection

Recommended Posts

I have a terrain engine up and running. I would like to have more than just one texture in my engine. e.g. grass or dirt. I would like to have snow, dirt, grass, water, rock, and after certain heights on my greyscale height map values change to a different texture for those polygons. I can''t figure out how to do this. Why? well I can''t call glBindTexutre() in the middle of a for loop using glBegin() and glEnd(). So take it easy on me I am still learning OpenGL. Thanks

Share this post


Link to post
Share on other sites
Well, possibly the simplest way to do this would be to store multiple textures within one - for example:

0........64......128
. . .
. Grass . Snow . Y
. . .
64.......64......64

X

Basically, as regards texturecoordinates, x<0.5 in the texture would then be grass, and x>0.5 would be snow. This has the advantage that you can render lots of different textures within a single glbegin() glend() clause.

As you want more and more textures, you''ll need to create some better logic to find textures from within a grid.

If you want to see a practical application of all of this, check out NEHE for bitmap fonts in OpenGL...

Share this post


Link to post
Share on other sites
I have used texture coordinates before to display text. So that is ok, but won''t my textures be very low quality due to the size has been reduced? And I take it their is no other way to do this if you are using a


for()
glBegin()
for()
glEnd()


structure of code.

So I suppose I will need to have my texture as large as possible to hold as many higher resolution textures as possible? Thanks

Share this post


Link to post
Share on other sites
use a big texture (but you probably shouldnt go higher than 1024x1024) to avoid changing the texture all the time. if you want more than one texture at the same time without multiple passes (and for terrain i would try to use few as possible) look into multitexturing.

Share this post


Link to post
Share on other sites
The issue here is that you can''t call a glBindTexture() with in the glBegin() and glEnd() blocks of code. So what happens if I have a Y value that is greater than the height I need to start texturing rock or snow terrain? I can''t, or you suggesting I use a break and somehow restart the texturing at that point again?

Share this post


Link to post
Share on other sites
I hate to break it to you, but if you are actually doing a "serious" terrain engine, then your question is a moot point really.

The reason is you shouldn''t be using glBegin/End when rendering an entire terrain. Use vertex array or buffer objects instead.

I guess what I am saying, and this isn''t a flame, is read up on the vertex arrays FIRST. I 100% guarantee you that you will eventually switch your terrain to using them anyways (unless you literaly have no intention of doing anything beyond a class project).

So even if you solve your problem now, using glBegin/end, then the solution would not even be valid any more once you end up switching to vertex arrays.

I know, I know, I didn''t answer your question at all, but seriously my intention is in helping you out


Share this post


Link to post
Share on other sites
quote:
Original post by duke
I hate to break it to you, but if you are actually doing a "serious" terrain engine, then your question is a moot point really.

The reason is you shouldn''t be using glBegin/End when rendering an entire terrain. Use vertex array or buffer objects instead.

I guess what I am saying, and this isn''t a flame, is read up on the vertex arrays FIRST. I 100% guarantee you that you will eventually switch your terrain to using them anyways (unless you literaly have no intention of doing anything beyond a class project).

So even if you solve your problem now, using glBegin/end, then the solution would not even be valid any more once you end up switching to vertex arrays.

I know, I know, I didn''t answer your question at all, but seriously my intention is in helping you out





I am already using a display list to render my terrain engine. I have read some on the vertex arrays but haven''t gotten into them yet. Thanks and any ideas on how to implement it would be nice.

Share this post


Link to post
Share on other sites