[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

OpenGL texture mapping

Posted on 2000-09-26
7
Medium Priority
?
409 Views
Last Modified: 2010-08-05
How can I map a texture automatically in OpenGl ???
I tried to use OpenGl's automatic texture coord generation, but it don't seems to work.
mad666@infovia.com.ar
0
Comment
Question by:mad666
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 4460143
Hi mad666,

what object do you have on which you want to apply a texture? Is your question about loading a texture into OpenGL or is it about generating texture coordinates?

Ciao, Mike
0
 
LVL 5

Accepted Solution

by:
TheNeil earned 1000 total points
ID: 4460329
This is not an easy problem. I've used the tutorials (and components) from NeHe and what I came up with two solutions (one nice, easy, and ok, and another which is horendous, 'perfect', and unworkable).

The best way I found was to do this:

Deal with only two dimensions (forget about the third, it makes things way too complex). Using your two chosen dimensions, find the maximum and minimum co-ordinate values in each of them. You can then 'projec' the texture onto the object by simply finding out where the projected shape lies within the rectangle defined by the maximum and minimum values. You then just need to scale everything to be in the range 0to 1.

If you need some code then just ask and I'll see what I can do

The Neil =:)
0
 

Author Comment

by:mad666
ID: 4466142
Send me code please...
0
 
LVL 10

Expert Comment

by:Lischke
ID: 4469860
mad666, you should accept an answer after you have seen the code not before. It could  well be that I had given you better code (although TheNeil's is surely not bad either).
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 4478063
Thanks Lischke (I think).

As for some code then this is what I use:

  PROCEDURE CalculateMapping(ax, ay, az, bx, by, bz, cx, cy, cz : REAL;
                                  rMaxX, rMinX, rMaxY, rMinY, rMaxZ, rMinZ : REAL;
                                  VAR p1x, p1y, p2x, p2y, p3x, p3y : REAL;
                                  iMapDir : LONGINT);
  VAR
    rSx : REAL;
    rSy : REAL;
    rSz : REAL;
  BEGIN
    rSx := 1 / ABS(rMaxX - rMinX);
    rSy := 1 / ABS(rMaxY - rMinY);
    rSz := 1 / ABS(rMaxZ - rMinZ);

    CASE iMapDir OF
      0 : BEGIN     //Side
            p1x := (ax - rMinX) * rSx;
            p2x := (bx - rMinX) * rSx;
            p3x := (cx - rMinX) * rSx;
            p1y := (ay - rMinY) * rSy;
            p2y := (by - rMinY) * rSy;
            p3y := (cy - rMinY) * rSy;
          END;
      1 : BEGIN     //Top
            p1x := (ax - rMinX) * rSx;
            p2x := (bx - rMinX) * rSx;
            p3x := (cx - rMinX) * rSx;
            p1y := (az - rMinZ) * rSz;
            p2y := (bz - rMinZ) * rSz;
            p3y := (cz - rMinZ) * rSz;
          END;
      2 : BEGIN     //Front
            p1x := (az - rMinZ) * rSz;
            p2x := (bz - rMinZ) * rSz;
            p3x := (cz - rMinZ) * rSz;
            p1y := (ay - rMinY) * rSy;
            p2y := (by - rMinY) * rSy;
            p3y := (cy - rMinY) * rSy;
          END;
    END;
  END;

It gets called like:

      GetXRange(rMinX, rMaxX, iObjectMatch);
      GetYRange(rMinY, rMaxY, iObjectMatch);
      GetZRange(rMinZ, rMaxZ, iObjectMatch);

            CalculateAlphaMapping(<Point 1.x>, <Point 1.y>, <Point 1.z>,
                             <Point 2.x>, <Point 2.y>, <Point 2.z>,
                             <Point 3.x>, <Point 3.y>, <Point 3.z>,
                             rMaxX, rMinX, rMaxY, rMinY, rMaxZ, rMinZ,
                             px[1], py[1], px[2], py[2], px[3], py[3],
                             <Mapping Direction>);

The results get placed into the three arrays px, py, and pz (all of which are defined as ARRAY [1..3] OF REAL). These then contain the mapping values for each of the three points. You will need to write the three routines to get your point ranges (in the above code mine are called GetXRange, GetYRange, and GetZRange). These though are a total doddle as they just iterate through your co-ordinate data and find the maximum and minimum values

Hope this is what you're after (and hope it justifies the points)

The Neil =:)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question