Jump to content
  • Advertisement
Sign in to follow this  
Kitt3n

OpenGL fbo & texture size

This topic is 2854 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

I'm learning openGL and have some questions on FBO's and texture sizes.
Assume my the window is 960x640 pixels. I understand that textures are preferably power-of-two, which means I need a 1024x1024 depth & color-texture in my FBO.
However that will change the aspect-ratio from my rectangle-window to a square texture and either mean stretching or only using a part of the 1024 texture.

Questions:
1. Is the aspect-ratio issue bad (stretching into texture & unstretching to window )?
2. Should I try to only use 960x640 pixels of this 1024x1024 texture?
3. When I try to use only 960x640 pixels (see rendertarget_push()), the image looks stretched - and on the right side a bar of 30 (or so) pixels is "missing" ? How to let it only use a small part of the 1024x1024 texture?

Regards


bool rendertarget_push( RenderDevice* _context, RenderTarget* _rt )
{
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _rt->fbo);
glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT);

glViewport(0, 0, _context->w, _context->h); // 960x640
//glViewport(0,0, _rt->w, _rt->h); // 1024x1024

glViewport(0,0, _rt->w, _rt->h); //_context->w, _context->h);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, _rt->depthbuffer, 0);
}

bool renderDevice_rendertarget_pop (RenderDevice* _context)
{
glPopAttrib();

glDrawBuffer(GL_BACK)
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glDrawBuffer(GL_BACK);
glReadBuffer(GL_BACK);
}

void renderDevice_render (RenderDevice* _context, Scene* _scene)
{
rendertarget_push (_context, _context->rt);
{
renderDevice_clear (_context);
glUseProgram(_context->m_simpleProgram.program);
< render the 3d scene >
glUseProgram(0);
}
renderDevice_rendertarget_pop(_context);


// copy rendertarget to backbuffer
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _context->rt->texture);
glActiveTexture(GL_TEXTURE0);

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f( 1.0f, -1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();
}
}






vertex shader

attribute vec2 Position;
attribute vec2 TextureCoordIn;

varying vec2 TextureCoord;

void main(void)
{
gl_Position = vec4(Position.xy, 0.0, 1.0);
TextureCoord = TextureCoordIn;
}

pixel-shader

varying vec2 TextureCoord;
uniform sampler2D Sampler;

void main(void)
{
vec3 color = texture2D(Sampler, TextureCoord).xyz;
gl_FragColor = vec4(color, 1);
}



Share this post


Link to post
Share on other sites
Advertisement
Quote:

Assume my the window is 960x640 pixels. I understand that textures are preferably power-of-two, which means I need a 1024x1024 depth & color-texture in my FBO.


Just use a 960x640 pixel fbo. The power of two requirement is ancient, and I don't think it's important anymore.

Share this post


Link to post
Share on other sites
I just noticed the following extension on osx: GL_ARB_texture_non_power_of_two.
I assume that if this is supported, I can safely use 960x640.

Tried the iPhone simulator and it doesn't support this extension (however it also seems to work there). Haven't tried the device though.

Anyone have any experience with non-pot textures on iPhone?

Share this post


Link to post
Share on other sites
I think power of 2 textures are still a little bit faster, but it doesn't matter so much anymore.

also when u use a 1024x1024 texture for your smaller screen you won't see any strechting, it all depends on your projektion matrix.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!