PDA

View Full Version : Window, and polygon texture



Adrian Hooper
03-20-2009, 04:20 AM
I have a couple of questions.

1. I've rendered a room and one wall I want to have a window. I've created it with GL_QUADS, but how do I now add a window into this wall and make it transparent? Do I have to re-do the wall or can I add something on top?

2. The room is not a simple cube, it is oddly shaped. How can I apply a texture to the floor like this without skewing it? How do I calculate the points for it?

This is the floor:

gl.glBegin(GL.GL_POLYGON);
gl.glColor3f(1.0f*scale_Factor, 1.0f*scale_Factor, 1.0f*scale_Factor);
gl.glVertex3f(-75.0f*scale_Factor,-50.0f*scale_Factor,0.0f*scale_Factor);
gl.glVertex3f(75.0f*scale_Factor,-50.0f*scale_Factor,0.0f*scale_Factor);
gl.glVertex3f(75.0f*scale_Factor,-50.0f*scale_Factor,200.0f*scale_Factor);
gl.glVertex3f(-30.0f*scale_Factor, -50.0f*scale_Factor, 200.0f*scale_Factor);
gl.glVertex3f(-30.0f*scale_Factor, -50.0f*scale_Factor, 250.0f*scale_Factor);
gl.glVertex3f(-75.0f*scale_Factor, -50.0f*scale_Factor, 250.0f*scale_Factor);
gl.glVertex3f(-75.0f*scale_Factor, -50.0f*scale_Factor, 150.0f*scale_Factor);
gl.glVertex3f(-55.0f*scale_Factor, -50.0f*scale_Factor, 150.0f*scale_Factor);
gl.glVertex3f(-55.0f*scale_Factor, -50.0f*scale_Factor, 100.0f*scale_Factor);
gl.glVertex3f(-75.0f*scale_Factor, -50.0f*scale_Factor, 100.0f*scale_Factor);
gl.glVertex3f(-75.0f*scale_Factor,-50.0f*scale_Factor,0.0f*scale_Factor);
gl.glEnd();

Cheers guys

Rosario Leonardi
03-20-2009, 06:37 AM
1 - The best way to do such things is to open blender, model the room as you like, export in any format you can read in C++ and then read the model in your program.
The other way is to compute the point of the quads by hand.. an incredible waste of precious time.
I don't suggest you tu apply an alpha texture, this could lead to fuzzy edge window and other problem (bad blending, etc).

2- Again, the best way is to apply the texture in blender, but if you have the vertex position you can simply compute the planar projection of the texture (planar projection on a plane should works fine :) ).
If a vertex is in position [x, 0, z] the texture coordinate will be [x, z] * scale factor.
Where scale factor is how big is your texture.

Adrian Hooper
03-20-2009, 06:53 AM
Ok the floor is now texturing but just looks like digital noise. When you say the size of the texture, you mean the dimensions? ie it's 250x250 so multiply by 250?

WillsB
03-20-2009, 09:13 AM
If you multiply the tex coords by 250, then you will have a texture that repeats 250 times along the axis whos texture coordinates you have multiplied (I think this is right...). Oh and you'll need to set your glTexParameterf to GL_REPEAT for it to tile too (or youll just get one tiny copy of your texture in the center of your plane).