Making a Border around texture
I''m trying to create a white border around a texture.
glTexImage2D suppose to have a border but i have''nt gotten it to work
I use read pixels to load the data off the screen.
then use glTexImage2D to load the data into a texture.
BGCJR
Game Core
If your border is an uniform color, then you don''t need to send the border texels to the graphics card and you should use the texture border color with something like :
Secondly, texture border does NOT belong to the texture quad (0,0)-(1,1).
Texture border is used for sampling texels that are "close to the border".
For instance in bilinear filtering, 4 neighbours texels are used in interpolation equations. When those 4 texels are in the "middle" of the texture then there''s no problem. But when those 4 texels are in the "edge" of the texture, some texels should be read "out of range", so what happens ? OpenGL use texture border of course.
What you have to know is that texture border is not meant to be displayed. It helps solving problems for sampling "out of range" texels.
If you want to outline your texture you should include your white texels INSIDE the texture. If you have a 16x16 texture, then the 1st row, 1st column, 16th row and 16th column should be white.
If you use a 18x18 texture with white borders, you probably won''t notice that you have white texels.
Also if you want to outline you could display wireframe with thick lines but that''s a bit slower and it''s depth-independant.
GLfloat white_color[] = { 1.f, 1.f, 1.f, 1.f };glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, white_color);
Secondly, texture border does NOT belong to the texture quad (0,0)-(1,1).
Texture border is used for sampling texels that are "close to the border".
For instance in bilinear filtering, 4 neighbours texels are used in interpolation equations. When those 4 texels are in the "middle" of the texture then there''s no problem. But when those 4 texels are in the "edge" of the texture, some texels should be read "out of range", so what happens ? OpenGL use texture border of course.
What you have to know is that texture border is not meant to be displayed. It helps solving problems for sampling "out of range" texels.
If you want to outline your texture you should include your white texels INSIDE the texture. If you have a 16x16 texture, then the 1st row, 1st column, 16th row and 16th column should be white.
If you use a 18x18 texture with white borders, you probably won''t notice that you have white texels.
Also if you want to outline you could display wireframe with thick lines but that''s a bit slower and it''s depth-independant.
One thing you can try is something like this:
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, myTex);
glBegin(GL_QUADS);
glTexCoord2i(0, 0); glVertex3f(0.0, 0.0, 0.0);
glTexCoord2i(1, 0); glVertex3f(1.0, 0.0, 0.0);
glTexCoord2i(1, 1); glVertex3f(1.0, 1.0, 0.0);
glTexCoord2i(0, 1); glVertex3f(0.0, 1.0, 0.0);
glEnd();
glDisable(GL_TEXTURE_2D)
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_LOOP);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glVertex3f(1.0, 1.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glEnd();
Which just draws the outline of the quad overtop of the existing quad, giving you a white "border"
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, myTex);
glBegin(GL_QUADS);
glTexCoord2i(0, 0); glVertex3f(0.0, 0.0, 0.0);
glTexCoord2i(1, 0); glVertex3f(1.0, 0.0, 0.0);
glTexCoord2i(1, 1); glVertex3f(1.0, 1.0, 0.0);
glTexCoord2i(0, 1); glVertex3f(0.0, 1.0, 0.0);
glEnd();
glDisable(GL_TEXTURE_2D)
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_LOOP);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glVertex3f(1.0, 1.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glEnd();
Which just draws the outline of the quad overtop of the existing quad, giving you a white "border"

---I write code.DelphiGL (http://delphigl.cfxweb.net)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement