Results 1 to 3 of 3

Thread: Preserve a texture's size

  1. #1
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    2

    Preserve a texture's size

    Hi all,

    I've been playing around with writing my own window manager in Linux similar to Compiz. I've managed to successfully create a texture out of the contents of a window, but now my problem is I can't figure out how to draw that texture without making the texture look blurry (the blurriness is a result of the texture being scaled).

    Basically I need a way to create a rectangle with the necessary dimensions so that the texture doesn't end up scaled. Is this possible? How does Compiz do it?

    thanks!

  2. #2
    V-man
    Guest

    Re: Preserve a texture's size

    You can stay with 2D textures with POW2 dimension. If image is 100x 60 pixels, make a texture of 128x64 and fit the image into the lower left corner of the texture. Texcoords would be
    0.0 to 100.5/128.0 in the S direction
    0.0 to 60.5/64.0 in the T direction

    or if you have GL 2.0, just make a 100x60 GL_TEXTURE_2D

    or if you have GL_ARB_texture_rectangle

  3. #3
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    2

    Re: Preserve a texture's size

    I figured out how compiz does it, and it's basically some simple perspective trickery. We can set the camera's position such that the height/width of the viewport at Z = 0.0f is 1.0f. This means if we divide the width of the texture by the width of the screen, we'll have the correct size of the primitive.

    To determine where the camera needs to be to get this 1x1 size viewport, we use some simple trig. What we need is this: a plane of size 1.0f x 1.0f that, when positioned at Z=0.0f, will take up the whole screen. To do so, we draw a line from the center of this plane to the camera's position. This line bisects the 60 degree fov to create two 30 degree angles. We then can determine the length of this line using trig in order to give us the Z coordinate of the camera. For the 60 degree fov example, we have Z = (1.0f / 2) / tan(30) = 0.866025404. moving the camera back by this amount now means we have a 1x1 viewport at Z=0.

Similar Threads

  1. Mapping from rednerbuffer size to texture size for glow effect
    By 2Wheels in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-11-2013, 04:16 PM
  2. Should geometry shader preserve primitive order or am I just lucky?
    By shadocko in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 06-11-2012, 08:07 AM
  3. Zooming and Preserve aspect ratio
    By Jenk in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-17-2006, 06:53 AM
  4. ASE format texture vertices and faces/Texture Size
    By F_Kal in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-28-2004, 10:15 AM
  5. Texture Size and pict size
    By morzech in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-27-2002, 12:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean