|
Draw a textured quad in allegro5 |
cecco4
Member #15,659
June 2014
|
Hi, {"name":"L3n5KdT.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/8\/b800b45cc0a0e8cf867bb06e9754d50c.png","w":800,"h":600,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/8\/b800b45cc0a0e8cf867bb06e9754d50c"} Is it possible in Allegro? or i have to use OpenGL? |
Arthur Kalliokoski
Second in Command
February 2005
|
I'm pretty sure you need to use z values for the vertex locations as well, and rotate them with a matrix, otherwise you're trying to texture a trapezoid, which causes the effects shown. They all watch too much MSNBC... they get ideas. |
cecco4
Member #15,659
June 2014
|
Allegro manual said: Defines the generic vertex type, with a 3D position, color and texture coordinates for a single texture. Note that at this time, the software driver for this addon cannot render 3D primitives. If you want a 2D only primitive, set z to 0. Note that when you must initialize all members of this struct when you're using it. One exception to this rule are the u and v variables which can be left uninitialized when you are not using textures. Can this be a problem? Also, i didn't find any example of al_draw_prim using the z value . |
Todd Cope
Member #998
November 2000
|
These functions will help you get started: al_perspective_transform If you have already calculated the 3D coordinates (x, y, z) for all of your vertices, you should just be able to pass them to al_draw_prim() and let it handle the rest. |
Thomas Fjellstrom
Member #476
June 2000
|
A split texture like that makes me think you have the verticies in the wrong order. I think you want to make sure they are in CCW? And I prefer TRIANGLES vs TRIANGLE_FAN or TRIANGLE_STRIP. More data, but easier to process. -- |
Arthur Kalliokoski
Second in Command
February 2005
|
This image shows a trapezoid 2d layout of a brick wall on the left half, and the right half shows a proper rectangular image that's rotated. {"name":"609058","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/6\/268557f9316ad50b613540449d867ad8.png","w":810,"h":629,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/6\/268557f9316ad50b613540449d867ad8"} The program and image (warp.c and brick2.jpg) are in the paperclip. [EDIT] I left an orthogonal matrix in it (glFrustum on line 124), change it to gluPerspective(90.0,4.0/3.0,1.0,30.0); and it'll look a bit better but the effects still the same. They all watch too much MSNBC... they get ideas. |
cecco4
Member #15,659
June 2014
|
I tried to change some z value but it doesn't affect anything in the texture since i go off-bounds (-1:+1) and it start to disappear: Arthur Kalliokoski's example works fine but i never used OpenGL and i have some problem with the vertex coordinate. |
Arthur Kalliokoski
Second in Command
February 2005
|
The parts that exceed -1.0 - 1.0 are "disappearing" because the normal 2D transform has set the viewing frustum near and far values to -1 and 1. You need to use al_perspective_transform() as Todd Cope said. I haven't learned how to use A5 built in transform stuff myself, but I'll try to hack on it for 30 minutes to see if I can get it to work as in the OpenGL example above. [EDIT] AAAaannd I failed to do it. I was looking at ex_projection.c in the examples. Maybe somebody who knows can help? They all watch too much MSNBC... they get ideas. |
cecco4
Member #15,659
June 2014
|
I studied a bit openGL and understood the basic coordinate system, however i think i simply need some image manipulation that took the bmp and stretch it in four point. |
Arthur Kalliokoski
Second in Command
February 2005
|
The perspective correct texture mapping uses the rotation matrix to do that automatically using several "math chips" at once. Or should I say it does scan lines per triangle, which the orthographic trapezoid shows where the edges are, but the calculation differs for each triangle. They all watch too much MSNBC... they get ideas. |
cecco4
Member #15,659
June 2014
|
I think this can be useful, but i don't understand the x,y,z used. |
|