🔒 Locked
TEXTURE BORDERS
Advertisement
Original Post
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.
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.
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 ?
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);
}
{
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);
}
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
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
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
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
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 :
[edited by - vincoof on July 25, 2002 10:28:02 AM]
*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]
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
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
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
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
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement