PDA

View Full Version : texture sizes



ajbiv
02-23-2009, 02:07 PM
I have a 48x48 image that I draw as a texture. The texture is resized to look odd. I understand that the texture is being mapped to my coordinate space and since my width is greater than my height, it looks funny. How can I turn this off? I want to draw as 48x48.

ZbuffeR
02-23-2009, 03:18 PM
http://basic4gl.wikispaces.com/2D+Drawing+in+OpenGL
http://www.gamedev.net/community/forums/topic.asp?topic_id=104791

If you problem is about Power-Of-Two / Non-Power-Of-Two textures, feel free to ask for more info.

ajbiv
02-23-2009, 05:47 PM
yeah...i'm past that i hope :)

here is what i'm trying to do. I've been struggling with it for a while.

I have a drawing program. This drawing program utilizes a FBO as a texture for the "canvas". I load a PNG as the starting point for the drawing. This PNG serves as the background for my drawing.

Everything seems to work great before I attempt this.
What i want to do is double the width of my "canvas" and show only part of it. Conceptually, allow the user to scroll left/right on the canvas.

Any thoughts on how to accomplish this.

// -- (fx) draw view ---

// setup main drawing
glOrthof(0, imgWidth, 0, imgHeight, -1, 1);

glViewport(0, 0, backingWidth, backingHeight);

// draw rect 0,0,imgWidth,imgHeight
// with offscreen texture


// -- f(x) draw user's movement

// setup drawing from the user (mouse)
glOrthof(0, backingWidth, 0, backingHeight, -1, 1);
// draw lines from the user's mouse coordinates

scratt
02-23-2009, 06:58 PM
Could this not be done quite simply with texture coords, or even simply geometry coordinates?

With tex coords in x run from 0.0 - 0.5 <-> 0.5 - 1.0
And with the QUAD simply make it twice the effective screen width where it is drawn, and then "scroll" it left and right?

Perhaps I am missing something..
I presume you are drawing the texture from the FBO onto a full screen QUAD.
If so it seems trivial to affect either it's texture coords or the actual coordinates of a QUAD twice the width of the screen to give this effect....

ajbiv
02-23-2009, 08:43 PM
i tried some stuff like that, but i will give it another try now that i have some basic direction. thanks

ajbiv
02-27-2009, 05:36 PM
I am still struggling, but I simplified my program to be as simple as possible.

I'm unclear.

If i want my "drawing" twice the size of my view what do i do?

in this code, i can use the texture coords as 0.0 - 0.5 and see that I only get half my background image. However, how to I effectively "scroll". Also, I'm confused on what my viewport and ortho should be when my drawing is twice the size of my view and I only want to show part of the view as i scroll left to right.



glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glViewport(0, 0, backingWidth, backingHeight);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0, screenWidth, 0, screenHeight, -1, 1);
glMatrixMode(GL_MODELVIEW);

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);


GLfloat maxT = [_textures[kTexture_Background] maxT];
GLfloat maxS = [_textures[kTexture_Background] maxS];
GLfloat coordinates[] = {
0, maxT,
maxS, maxT,
0, 0,
maxS, 0
};

GLfloat vertices[] = {
0, 0, 0,
screenWidth, 0, 0,
0, screenHeight, 0,
screenWidth, screenHeight, 0
};

glBindTexture(GL_TEXTURE_2D, [_textures[kTexture_Background] name]);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

scratt
02-27-2009, 07:40 PM
Well if your texture coords go from 0.0 - 1.0 in both axis then you will get the whole texture. The idea with going from 0.0 - 0.5 is, as you saw, you get get half the texture.

To scroll just increase both texture coord values by the same amount.
For example..
(0.0,0.5)...(0.1,0.6)...(0.2,0.7).. and so on.. This will always show half the texture, but gradually moving it left as you increase the texture coordinates.

If you are using an Ortho view then you can map the QUAD coords one to one on the screen. So if your screen size is say 1000x1000, then make the QUAD that size also with it's origin (left corner) at (0.0,0.0)

The act of scrolling the texture is what makes it move across the screen.

ajbiv
02-28-2009, 01:30 PM
ahh that makes total sense now. i really appreciate the help.