PDA

View Full Version : How to setup the parameters for facades



anime.igala.net
12-01-2008, 03:01 AM
Hello all,

I'm beginner to OpenGL.

I would like to draw a wall look like this:

http://fun.igala.net/images/opengl%20texture.jpg

I have setup some OpenGL parameters like this:

[CODE]
//------------ texture

//
int textureID[1];
int texture_w = 4, texture_h = 4;
unsigned char* texture_data = NULL;

loadTextureData(texture_data);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glGenTextures ( 1, textureID );
glBindTexture ( GL_TEXTURE_2D, textureID[0] );

int bpp = 3;
glTexImage2D ( GL_TEXTURE_2D, 0, bpp==3 ? GL_RGB : GL_RGBA, texture_w, texture_h, 0, bpp==3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, texture_data);

//glTexEnvx ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexCoordPointer( 2, GL_FLOAT, 8*sizeof(float), vertices );

// How to setup the parameters?

//=======================
// draw texture here
//=======================

free(texture_data); // Free The Image Structure

glDeleteTextures(1, textureID);

[/B][/QUOTE]

But I don't know how to continue. Could you please help me?

Thanks,

_NK47
12-01-2008, 03:21 AM
But I don't know how to continue.
me neither. depends on what you have so far and what the actual problem is.

anime.igala.net
12-01-2008, 03:38 AM
But I don't know how to continue.
me neither. depends on what you have so far and what the actual problem is.

I have the image texture already.
I have also a class that contains the parameters (XScale, YScale, XPosition, XRepeatInterval ...).

Imagine that I have already all parameters. Now, how to setup OpenGL?

THanks,

_NK47
12-01-2008, 03:42 AM
you want your image on a plane in 3d space or in 2d covering the screen?

anime.igala.net
12-01-2008, 04:09 AM
I'm drawing the buldings in 3d space.

_NK47
12-01-2008, 05:21 AM
build a model (cube or plane) and before drawing them bind the texture you need. that way the texture is put on top of your geometry and everything should work. something like this (plane):

glBindTexture(GL_TEXTURE_2D,textureID);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(...);
glVertex3f(...);
glTexCoord2f(...);
glVertex3f(...);
glTexCoord2f(...);
glVertex3f(...);
glTexCoord2f(...);
glVertex3f(...);
glEnd()

anime.igala.net
12-01-2008, 05:35 AM
But how about the XScale, YScale, XPosition, XRepeatInterval ? OpenGL will do it automatically or I must do myself. For example, I have a texture with the width = 10, the size of wall is 50; So I have to use a for (i=0 to 5) ?

_NK47
12-01-2008, 07:06 AM
still trying to understand. OpenGL will map (stretch in your case) the texture automatically if your wall is larger then the texture. how the texture is mapped is assigned through texture coordinates - glTexCoord().
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texcoord.html

dletozeun
12-01-2008, 12:08 PM
OpenGL uses normalized texture coordinates (ie rectricted to [0..1] interval). However it is possible to give texture coordinates higher than 1 or lower than 0, these ones are either clamped or repeated. For example if you choose the repeat mode, OpenGL will ignore the integer part of the coordinates and use only the fractional one and that causes a repetition of the texture image on the mapped polygon.

To choose the wrapping mode look at the function glTexParameter (http://www.opengl.org/sdk/docs/man/xhtml/glTexParameter.xml).

You use this one just bind the correct texture and do this to allow the texture repetition over the mapped surface:



// s texture coordinate repetition
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
// t texture coordinate repetition
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);


If you use non power of two textures check that your hardware supports the extension GL_ARB_texture_non_power_of_two.