in this program,
https://www.allegro.cc/forums/thread/612527/981976#target
I've got pairs of 3d triangles making up a terrain. I also subdivide them into powers of 2, depending on how close the camera is to the middle of the 2 triangles' shared edge.
I want to draw the triangles with the 3 corner colours interpolated smoothly blended with a repeating procedurally generated detail texture.
I'm wondering if there's a way to draw a normal triangle, like this
glBegin(GL_TRIANGLE_STRIP); glColor3d(0.75,0.25,0.25); glVertex3d( 0,1,0 ); glColor3d(0.25,0.75,0.25); glVertex3d( 1,0,0 ); glColor3d(0.25,0.25,0.75); glVertex3d( 1,1,0 ); glEnd();
with a repeating texture modifying the colour of each pixel in the triangle. The detail textures in Deus Ex are my inspiration for wanting to do this.
Sorry if there's an obvious answer I should have found.
Assuming you're using Allegro and you have loaded the texture into a bitmap, then
GLint tex = al_get_opengl_texture(allegro_bitmap); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, tex); glBegin(GL_TRIANGLES); glTexCoord3d(tu, tv) /* Define the rest of this vertex */ ... more vertices ...
tu and tv are texture coordinates. In OpenGL by default those are from 0 (left and bottom) to 1 (right and top).
I tried what you suggested, but the program crashes now. Is there a short example program that just loads a .png and draws a textured triangle?
edit:
I attached the program I'm working on
here's some of the code I'm using(example):
The code I posted will not crash as long as allegro_bitmap is valid.
Thanks. I'm gonna try http://wiki.allegro.cc/index.php?title=2D_using_OpenGL, and I'll edit if I get it to work.
edit:
I'm embarrassed to say I couldn't get it to work. Is there an example program anywhere that draws textured triangles?