Jump to content
  • Advertisement
Sign in to follow this  
OOBradm

OpenGL Creating a wireframe heightmap...

This topic is 4214 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Given any .jpg, I am trying to write code that will map the z coordinate to the color of the pixel. So its essentially a height map with the z value = the color of the image pixel. I have the code for what i've described above working alright, however I have some questions about how to render it in OpenGL. I want to be able to switch back and forth between filled polygons and wireframe mode. After looking this up, the glPolygonMode() seems to satisfy this desire by sending either GL_LINES or GL_FILL. BUT, Im not sure how and in what order to draw the vertices to make the wireframe look proper. my pseudo code looks like : for( y axis) for( x axis) get color of pixel and find z value draw pixel to screen end for end for the problem with this is that glBegin( GL_POLYGON ) draws one MASSIVE polygon and the screen looks horrendous. Im not sure of the proper way to draw vertices to the screen for wireframe and for filled. Can anyone help me out? Thanks, Brad

Share this post


Link to post
Share on other sites
Advertisement
If you use GL_POLYGON it will draw one big closed polygon as I recall. It might be a good idea to break it into triangles and GL_TRIANGLES instead. This could probably make your wireframe look better as well.

Share this post


Link to post
Share on other sites
Quote:
Original post by CRACK123
If you use GL_POLYGON it will draw one big closed polygon as I recall. It might be a good idea to break it into triangles and GL_TRIANGLES instead. This could probably make your wireframe look better as well.


I found out my biggest problem was using GL_LINES instead of the correct GL_LINE. Now I am basically using triangle strips and grouping the rows in twos to draw them.... ie:

=============================
=============================
=============================

where each one of those ======== is a triangle strip. Now, i'd like to apply a texture to this big wireframe I have. Is this the proper way to draw a wireframe in order to prepare for texturing?
Thanks,
Brad

Share this post


Link to post
Share on other sites
Afaik GL_POLYGON needs all vertices lying in a plane, so it wouldn't even work for hightmaps.

As for rendering the terrain:
You're on a good way using GL_TRIANGLE_STRIPs. You could however link the rows by "zero-area" triangles, i.e. you create one large triangle strip to hold the entire patch and inserting the first and last vertex of a row twice so that the resulting triangles have zero size (they technically would be lines since two of their vertices are identical).

Consider the following example (:

0-1-2
|\|\|
3-4-5

3-4-5
|\|\|
6-7-8

(the two strips are adjacent, but separated for illustration)

You have two strips made of the vertices 0 - 8.
The order of the vertices in the first strip is: 3,0,4,1,5,2
The order of the vertices in the second strip is: 6,3,7,4,5,8

Now you connect those two strips to form one:

3,0,4,1,5,2 (,2,6,) 6,3,7,4,5,8

Vertex 2 and 6 (in parentheses) is inserted to create the zero-area triangles (5,2,2), (2,2,6) and (2,6,6).

Now you have a single triangle strip made out of two. Do this to connect all your rows and you get a single triangle strip for your patch which saves you MANY draw calls.


Texturing:

The layout of your vertices basically doesn't affect texturing. Specify some texture coordinates (for example use location_of_vertex / dimension of patch) for use with a single texture. Note that texturing a wireframe doesn't make much sense, so use GL_FILL.

Later you may want to look into multitexturing techniques for terrain like detail maps or texture splatting.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!