View Full Version : Texturing Repeat and other questions...
08-16-2011, 04:25 AM
I am starting with opengl and I already got it a lot...but still in problems....
lets go my questions...
1-How do I repeat a texture in a face?? for example...I made a square that is my floor with grass texture, but when i apply it it stretch the image and become very visible and large the pixels...how do i solve this??
2-This is simple curiosity...whats the diference between GLfloat and float? or GLint and int???and so on??
3-How is the best struct code of opengl?? explaining, where to put the drawing ( in a loop for example), where to create things... there is some tutorial explaining how to gain performance by structing the code organized??
thanx to all for the attention...
08-16-2011, 04:31 AM
1: simply multiply your texture coordinates in both u and v to whatever times you want the repeat to be done. Ie: if u and v lie in [0..1] you have only the image, without repetition, if they lie into [0..10] you have 10 times the image in u direction and 10 times the image in the v direction. You can also do that with the texture matrix.
2: normally none (my header has typedef float GLfloat). I can't ensure it will be the same everywhere.
08-16-2011, 05:11 AM
Point 1.: As _arts_ said multiple your tex coords with some number (you will see) for example 10. And also make sure GL_REPEAT is set in the texture parameter section (where you load your texture).
Point 2.: Depends on the implementation, i personally try to use GLfloat everywhere and typdef it with my own names as _arts_ does:
typedef myFloat GLfloat;
Hard question, too general :)
I think its better to buy a book OpenGL Super Bible for example and check out their sample codes along with it. Even after that there will be questions ... so i do also waiting for somebody to shed light on it.
08-16-2011, 06:55 AM
So, if i understand i have to set the parameter like this...
glTexParameter(GL_TEXTURE_2D, GL_WRAP_W, GL_REPEAT); // i dont remember if these are the right words..but i get it..
then in my primitive i do this...
glTexCoord2d(10.0, 10.0); glVertex3f(1.0f, 1.0f, 0.0f);
glTexCoord2d(0.0, 10.0); glVertex3f(-1.0f, 1.0f, 0.0f);
glTexCoord2d(0.0, 0.0); glVertex3f(-1.0f, -1.0f, 0.0f);
glTexCoord2d(10.0, 0.0); glVertex3f(1.0f, -1.0f, 0.0f);
2- in general i use GLfloat....
3- I will check some samples and study the code...
08-16-2011, 07:30 AM
Yes, and also let me point you to a sample of how GL_REPEAT should be used when you load the grass texture:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0,
GL_BGR_EXT, GL_UNSIGNED_BYTE, m_image);
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.