|
Can anybody explain to me how the u,v texture coordianates... |
ted_gress
Member #14,404
June 2012
|
Can anybody explain to me how the u,v texure coordinates work with the primitive addon? For example, what range are they in? 0 to 1? And what do you when mapping a square texture to two triangle faces joined as a quadrilateral? Thanks guys, Ted TwilightRaven Games |
SiegeLord
Member #7,827
October 2006
|
The first couple of questions are answered in the ALLEGRO_VERTEX documentation. I don't understand your last question very well... "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Arthur Kalliokoski
Second in Command
February 2005
|
He asks how to assign the u,v coords to triangles. Since the ALLEGRO_VERTEX doc says it's in pixels, and the primitive vertices are in pixels and assume ccw winding, and suppose the hypotenuse was from top right to bottom left, it'd be something like this with a 256x256 texture. {"name":"606560","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/e\/ee4fad063f15b8b9aa71b6ab00cf66b7.png","w":854,"h":476,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/e\/ee4fad063f15b8b9aa71b6ab00cf66b7"} They all watch too much MSNBC... they get ideas. |
ted_gress
Member #14,404
June 2012
|
You act like I don't read the documentation :-p Yeah, I tried 0,0 60,0 60,60, etc... for my texture (it is a 60x60 image). All I get is a solid pale blue, no texture. That's why I posted to make sure I was doing the u,v coordinates mapping to the texture correctly, seems I am. TwilightRaven Games |
Arthur Kalliokoski
Second in Command
February 2005
|
OK, let me try it myself (for the first time). Gimme 30-40 minutes. They all watch too much MSNBC... they get ideas. |
ted_gress
Member #14,404
June 2012
|
Image is 60x60 1
2
3
4 ALLEGRO_VERTEX v[3];
5
6 v[0].x = 10;
7 v[0].y = 10;
8 v[0].z = 1;
9 //v[0].color = WHITE_COLOR;
10 v[0].u = 0;
11 v[0].v = 0;
12
13
14 v[1].x = 300;
15 v[1].y = 300;
16 v[1].z = 1;
17 //v[1].color = WHITE_COLOR;
18 v[1].u = 60;
19 v[1].v = 60;
20
21
22 v[2].x = 300;
23 v[2].y = 10;
24 v[2].z = 1;
25 //v[2].color = WHITE_COLOR;
26 v[2].u = 60;
27 v[2].v = 0;
28 //Game::logger("Running tiledhalfterrainclass rendering of primitives");
29 al_draw_prim(v, NULL, terrain_texture, 0, 3, ALLEGRO_PRIM_TRIANGLE_LIST);
Should work, right? Or am I missing something major. TwilightRaven Games |
LennyLen
Member #5,313
December 2004
|
ted_gress said: You act like I don't read the documentation :-p That's because there are too many questions from people who haven't read the documentation. It can be a good idea to indicate that you have looked for an answer but have been unsuccessful.
|
ted_gress
Member #14,404
June 2012
|
I know. Just kidding around. I guess when it hits 3:32 AM (my time) my sense of humor is poor. TwilightRaven Games |
Arthur Kalliokoski
Second in Command
February 2005
|
Welp, took me a little longer than I thought. I had to insert colors into the vertex definitions, unlike the example code on http://www.allegro.cc/manual/5/al_draw_prim. Anyway, here's a zipfile to play with. [EDIT] Probably the vertices could have been in one struct, and only one al_draw_prim() call would have to be made, adjusting the 3 to 6. They all watch too much MSNBC... they get ideas. |
ted_gress
Member #14,404
June 2012
|
Thanks I'll check it out either tonight or tomorrow...its getting late. My vertices are not colored also, which may be part of the problem. Thanks. TwilightRaven Games |
Arthur Kalliokoski
Second in Command
February 2005
|
I tried it your way (where you commented them out) but the compiler complained, I assume that's why you commented them out. If you play with those colors to be other than white, they'll tint the texture. Maybe this is because Linux uses OpenGL? If DirectX is different, it's a bug? They all watch too much MSNBC... they get ideas. |
SiegeLord
Member #7,827
October 2006
|
You definitely have to specify the color... the documentation is wrong in that part... jokes on me for referring you there, I suppose . "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Elias
Member #358
May 2000
|
SiegeLord said: You definitely have to specify the color... the documentation is wrong in that part
Quote: Note that when you must initialize all members of this struct when you're using it. I think it's pretty clear. (emphasis added by me) -- |
SiegeLord
Member #7,827
October 2006
|
I meant the example here: http://www.allegro.cc/manual/5/al_draw_prim "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
ted_gress
Member #14,404
June 2012
|
UPDATE I've got my texture mapping working now. Turns out the texture I was passing in was NULL. I'm still not quite sure why. I had something similar to this: 1...
2class A
3{
4public:
5
6ALLEGRO_BITMAP *getTexture() {
7return texture;
8}
9
10private:
11ALLEGRO_BITMAP *texture;
12}
13...........
14
15and then a function to load the texture
16
17A a;
18
19ALLEGRO_BITMAP *textureToLoad = a.getTexture();
20textureToLoad = al_load_bitmap(path);
21
22.....
I am assuming the problem comes when trying to change the private pointer member (*texture). I changed textureToLoad = al_load_bitmap(path) to and the problem resolved. So now I have a texture mapped nxn square surface made up on quads (that are made up of triangles) to work with. Next is adding a height map to adjust the z values of the quad surface. Yipee. :-) TwilightRaven Games |
|