Jump to content
  • Advertisement
Sign in to follow this  
TruckMack33

OpenGL texturing polygonal surface

This topic is 3686 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

Okay, this post is mainly orientated toward program layout. How should I program what I want. The actual code is secondary and will hopefully come in time. Some background is necessary before I jump in. I'm working on a project where the user draws objects in the program. The user starts in a 2d plain and plots line segments on it. There are two rules for whatever the user draws. 1) it must be enclosed (also dictates that it must have at least have 3 sides) 2) no segment may intersect another segment This part is easy, use the mouse event and populate a vector with the segments. Take the next sequence as an example of user input. It is a 2x2 square cented on the origin. Each pair of coordinates represents an endpoint. Each line represents a segment. X,Y > X,Y -1,-1 > -1,+1 -1,+1 > +1,+1 +1,+1 > +1,-1 +1,-1 > -1,-1 As far as I know, I can only draw triangles and quadratics in opengl. Using quads wouldn't make sense so I have to use triangles. The program that I hope to create will be able to divide this into triangles. To do this it must follow the following 2 rules. 1) Each additional segment must not intersect any other segment 2) The number of triangles equals the number of endpoints minus 2 Here is one possible solution. Each line contains 3 points that define the triangle. (-1,-1),(-1,+1),(+1,+1) (-1,-1),(+1,+1),(+1,-1) One concern is that this process might make some interesting triangles. Is there any any type of triangle it should try not to create? (i.e. very thin and long) Now, here comes the interesting part. How to texture it. Imagine the square in the example is a brick wall. Here are two concerns with the example. 1) If I arbitrarily apply a texture, the "bricks" of one triangle won't align with the bricks of the other triangle. 2) What if I want the texture to repeat multiple times over the surface? Maybe it's a big wall made of little bricks instead of a big wall of big bricks. I would appreciate an comment on the program layout and my concerns. I would appreciate any direction on the texture issue. [Edited by - macktruck6666 on July 15, 2008 9:50:26 PM]

Share this post


Link to post
Share on other sites
Advertisement
You can push triangles and quads to OpenGL, but the latter have to be convex to be rendered correctly. You can push more complex polygons if using glu (the OpenGL Utility library) routines.

Any pair of consecutive, co-linear line segments in a chain of segments reduces the "degree of sidedness" of the surrounded area by 1. So you need at least 3 non co-linear segments to get a polygon with a non vanished area.

The texture issue is a bit problematic since it seems that you doesn't know exactly what kinds of use cases are to be expected. The problem of unmatched texture pieces can perhaps be solved by using a separate texture mapping, similarly to those introduced by ray-tracers. E.g. a planar mapping (being co-planar with the "wall" onto which the polygons are constructed) defines the orientation, origin, and size and repetition of the texture. When a polygon is constructed, then its vertex positions are inversely mapped onto the texture plane, and the corresponding (u,v) tuples are determined therein.

Share this post


Link to post
Share on other sites
If I understand you correctly the user is drawing in a 2d plane, so you could lay out the texture in that plane. If you have an axis-aligned plane, e.g. the xz-plane, you could simply use the vertex coordinates as texture coords (i.e. use the x and z coords for the xz-plane) and scale them by your repetition factor. You can also either apply a rotation manually or use the texture matrix.

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!