Skip to main content
gamedev.net
🔒 Locked

TEXTURE BORDERS

Started by BGCJR Jul 22, 2002 at 8:38 PM 19 replies 800+ views
Original Post
BGCJR
BGCJR
I have tried create a texture with border but it''s too slow! is there a fast way to add a white border to a texture that is made ''on the fly''?
Game Core
omega_001
omega_001
After drawing the textured polygon, disable GL_TEXTURE_2D and draw a white outline around it using GL_LINES and the polygons geometry. Use glLineWidth to increase the size of the border.

Hope this helps.
BGCJR
BGCJR
I NEED THE TEXTURE TO HAVE A WHITE BORDER.
Game Core
vincoof
vincoof
I think that you render to texture using glCopyTexImage2D, right ?
If so, then you may set your border once, and then you don''t update all the texture every frame, using glCopyTexSubImage2D.

For instance, replace :
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, window_x, window_y, texture_width, texture_height, 0);
by :
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, border_size, border_size, window_x+border_size, window_y+border_size, texture_width-2*border_size, texture_height-2*border_size);

Where border_size is the width, in texels, of the fixed white border.
BGCJR
BGCJR
vincoof:
I''ve tried it, but, for some odd reason, it copies the visible scenes only.
So, I guess, the framebuffer is the last one i swapped buffers with?
Game Core
BGCJR
BGCJR
I''ve tried glOrtho for texture border.
I lost 1 fps. oh well.

Game Core
vincoof
vincoof
quote:
I''ve tried it, but, for some odd reason, it copies the visible scenes only.
So, I guess, the framebuffer is the last one i swapped buffers with?

I''m sorry but I quite don''t understand the problem. Maybe my english is not good enough ?

You should call glFlush or glFinish before copying your texture.
And before calling glCopyTexSubImage2D, you should do at least 1 call to glTexImage2D or glCopyTexImage2D because glCopyTexSubImage2D does NOT initialize the texture (read the specs or the red book and you''ll quickly see it).

Otherwise maybe your drivers/card does not support it correctly.
What card do you have ?
BGCJR
BGCJR
I''m using GF 256
Game Core
vincoof
vincoof
Hmm. I guess this card is good enough, and that the drivers are good enough too.
Would you please post the bit of code that copies the texture with glCopyTexImage2D and/or glCopyTexSubImage2D ?
BGCJR
BGCJR
static void generate_shadow_map(void)
{

GLfloat log2 = logf(2.0);



x = 1<<((int) (logf((float) width)/log2));
y = 1<<((int) (logf((float) height)/log2));

glViewport(0, 0, x, y);
shadowx= x; shadowy=y;

render_light_view2();


glEnable(GL_TEXTURE_2D);
/*
* Read in frame-buffer into a depth texture map
*/
glBindTexture(GL_TEXTURE_2D, SHADOWMAP2);
glTexParameterfv (GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, swBorderColor);
#ifdef GL_SGIS_depth_texture
if (do_proj)
#endif
// Reads Pixels of our little window depth into a depthBuffer.

{
if (glCopyTexImage2DEXT!=NULL)
glCopyTexImage2DEXT(GL_TEXTURE_2D, 0, GL_LUMINANCE,
0, 0, x, y, 0);

else

// glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, x-2, y-2);
glCopyTexImage2D(GL_TEXTURE_2D, 0,GL_LUMINANCE,// GL_RGBA,
0, 0, x, y, 0);
}
#ifdef GL_SGIS_depth_texture
else
{

glCopyTexImage2DEXT(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16_SGIX,
0, 0, x, y, 0);
}
#endif



///////////////////////////////////////////////////
// A Messy Way To Generate two or more ShadowMaps
/////////////////////////////////////////////////////
render_light_view();
glEnable(GL_TEXTURE_2D);
/*
* Read in frame-buffer into a depth texture map
*/
glBindTexture(GL_TEXTURE_2D, SHADOWMAP);
glTexParameterfv (GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, swBorderColor);
#ifdef GL_SGIS_depth_texture
if (do_proj)
#endif
{
if (glCopyTexImage2DEXT!=NULL)
glCopyTexImage2DEXT(GL_TEXTURE_2D, 0, GL_LUMINANCE,
0, 0, x, y, 0);

else

// glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 1, 1, x-2, y-2);
glCopyTexImage2D(GL_TEXTURE_2D, 0,GL_LUMINANCE,// GL_RGBA,
0, 0, x, y, 0);
}
#ifdef GL_SGIS_depth_texture
else
glCopyTexImage2DEXT(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16_SGIX,
0, 0, x, y, 0);
#endif

glColorMask(1,1,1,1);
glViewport(0, 0, width, height);

}
Game Core
BGCJR
BGCJR
i''ve got the border on the image. i used glOrtho with gl-line loop. but copying these images cuts fps by 1/4!
Any ideas? i''m still using glCopyTexImage2d.
Game Core
davepermen
davepermen
TexImage kills the old texture, reserves new mem and fills it with the data
TexSubImage copies the data onto the specified part of the texture

what you think? glCopyTexImage2D or glCopyTexSubImage2D is faster?

"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
davepermen
davepermen
how about this?
you GENERATE your texture on time.
glTexImage2D with all white as data

you update the texture in the range where you want it (means don''t update the borders)

glCopyTexSubImage2D(GL_TEXTURE_2D,0,
1,// the region where you begin to draw onto the texture (x)
1,// the region where you begin to draw onto the texture (y)
1,// the place where you start to copy from the screen (x)
1,// the place where you start to copy from the screen (y)
width-2, // the width of the copy
height-2 // the height of the copy
);

that way you don''t have to draw the border. instead you simply draw the rest.

"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
vincoof
vincoof
davepermen : hey, you're copying the advice I've written above

*SPOILER*
edit-I've hidden the solution !

BGCJR : use TexImage or CopyTexImage to initialize the texture object (allocate server memory and set the texture format), then ALWAYS call CopyTexSubImage, EVEN IF YOU COPY INTO THE WHOLE TEXTURE. It is significantly faster. (davepermen: sorry for answering the question !)

From the excellent Red Book :
quote:

Creating a texture may be more computationally expensive than modifying an existing
one. In OpenGL Release 1.1, there are new routines to replace all or part of a texture
image with new information. This can be helpful for certain applications, such as using
real-time, captured video images as texture images. For that application, it makes
sense to create a single texture and use glTexSubImage2D() to repeatedly replace
the texture data with new video images. Also, there are no size restrictions for
glTexSubImage2D() that force the height or width to be a power of two. This is
helpful for processing video images, which generally do not have sizes that are powers
of two.
(...)
Once again, the framebuffer itself can be used as a source for texture data; this time, a
texture subimage. glCopyTexSubImage2D() reads a rectangle of pixels from the
framebuffer and replaces a portion of an existing texture array.
(glCopyTexSubImage2D() is kind of a cross between glCopyTexImage2D() and
glTexSubImage2D() .)


[edited by - vincoof on July 25, 2002 10:28:02 AM]
davepermen
davepermen
dont answer questions not asked to you!!
i know that you''ve written it above. but he clearly states "Any ideas? i''m still using glCopyTexImage2d." so i thougth we should go into a
while(question.repeating()) answer.repeating();
now you kicked us out of the loop!

"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
BGCJR
BGCJR
Ok. I changed to pbuffer. i went from 26fps to 56fps.
But, Now, my white border is messed up!
I guess my grindstone is worn out. Maybe, A break!

You can dl my progress on shadowmapping made simple.
http://ice.prohosting.com/~bgcjr/shadowmap.ace

Game Core
vincoof
vincoof
WinAce keeps detecting that the file header is invalid. Have you tested the uploaded file ?
davepermen
davepermen
when drawing to pbuffer:

glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT|GL_OTHER_STUFF_YOU_WANT);
glEnable(GL_SCISSOR_TEST);
glScissor(1,1,pbuffer->width-2,pbuffer->height-2); //lookup the values, not sure if they are right that way...

draw into pbuffer

"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
BGCJR
BGCJR
davepermen: That works great! Framerate is better.
better late than never!

I''m using Winace 2.11 to compress my files.
It decompresses fine with it.

Remember, use latest drivers! This program requires them. And it doesn''t cost anything more to download them.
Game Core

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.