PDA

View Full Version : glTexCoord2f simple questions



blessman11
03-05-2011, 06:07 PM
whats units are glTexCoord2f assigned in?
is it 0-1

or

relative to image, texture size

Dark Photon
03-05-2011, 07:15 PM
whats units are glTexCoord2f assigned in?
is it 0-1 or relative to image, texture size
If you're using shaders (or texgen), it can be anything you want. Because you can modify it on the GPU before you're actually using it for texturing.

But if you're just using that texcoord directly (with or without shaders), it depends on the texture. With ordinary textures, it's 0..1. With rectangle textures, it's 0..res. And if you're using shaders. IIRC texelFetch will let you do 0..res.

_arts_
03-06-2011, 02:13 AM
It can be whatever.

With non rectangular textures, the thing is that the range [0.1] will give you the all image in the matching dimension (u or v). If your between [0..x] it will repeat the image x times. If you in the range [-x,0], it will reverse it.
This is true even if you're not using shaders.

If you use rectangular textures, then the range [0..w] (with w the width or height of the image) will give you a full dimension of the image. And I [B]think[B] it's the same as for non rectangular textures if you're over [0..w] or below 0.

blessman11
03-06-2011, 03:50 AM
With that in mind I'm wondering why my texture isn't being displayed properly. Could you look at my "glTexParameterf" or "glTexCoord2f" below or whether I could be missing something crucial.


void Init()
{glClearColor(1.0,0.0,0.0,1.0);
glEnable(GL_NORMALIZE);
MyBitmap = loadBMP("smile.bmp");
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, 3,MyBitmap->width /*checkImageWidth*/,
MyBitmap->height /*checkImageHeight*/, 0, GL_RGB, GL_UNSIGNED_BYTE,
MyBitmap->pixels/*&checkImage[0][0][0]*/);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glNormal3f(0.0f,0.0f,1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, 0.0);
glTexCoord2f(1, 0.0);glVertex3f(600.0, 0.0, 0.0);
glTexCoord2f(1.0, 1.0);glVertex3f(600.0, 337.0, 0.0);
glTexCoord2f(0.0, 1.0); glVertex3f(0.0,337.0, 0.0);


glEnd();
glFlush();
T[12]= xpos;
T[13] = ypos;
glLoadMatrixf(T);
glMultMatrixf(T1);

glutPostRedisplay();
glutSwapBuffers();
}

mobeen
03-06-2011, 06:38 AM
You should do the following calls at the point where u r loading the texture before glTexImage2D. Currently the texture is not bound to the GL_TEXTURE_2D binding point.



GLuint texID;

void init() {
MyBitmap = loadBMP("smile.bmp");
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glEnable(GL_TEXTURE_2D);
glGenTextures(1, &texID);
glBindTextures(GL_TEXTURE_2D, texID);
glTexImage2D(GL_TEXTURE_2D, 0, 3,MyBitmap->width,MyBitmap->height, 0, GL_RGB, GL_UNSIGNED_BYTE,MyBitmap->pixels);
//set texture parameters etc.

V-man
03-06-2011, 07:29 AM
Using values outside of the range from 0.0 - 1.0 causes corrosion of the pins of the processors. Did you try it? Do not try it.

_arts_
03-06-2011, 01:33 PM
:)