Total noob here learning openGL and I don’t have any code to post because this is a question about a concept, not my current implementation. If code is absolutely required let me know and to my nooby shame I will post some.
Basically I have a VBO that is displaying a 2D image in GL. However, since my viewport is 800×600 and the image is 1024×1024, the image is being scaled down to fit inside the viewport. I’ve googled for a very long time about this issue and all I can find are references to this in things such as the NeHe tutorials where they say this will happen, but with no explanation as to why and how to prevent it from happening. I think I found one forum that said it’s possible to prevent but again, no details.
So, I’m curious, how can this be done? I’m JUST learning GL so I’m pretty much a brand new baby noob in this area. If it helps, I’m making a 2D game and I’m trying to use this VBO for displaying the background image for a level, so as you move the camera left and right, up and down you’re essentially scrolling this background image. Any help would be greatly appreciated and thanks. 🙂
P.S. Also, I realize this probably should be in a separate question but any explanation or links to explain the coordinate system for vertex/texture maps would be appreciated as well. I’m not really grasping how one is supposed to map textures from 0-1 and convert that to pixel coordinates in space.
UPDATE
Okay so after some more googling the ONLY solution I’ve found is to adjust the viewport temporarily to be at least the size of your 2D texture, then draw your 2D texture, then set the viewport back to the window size (or whatever it ought to be). Like so:
//Set viewport so size of the current texture - note this is using a VBO
glViewport(0, 0, 1024, 1024);
glBindTexture(GL_TEXTURE_2D, texture);
glDrawArrays(GL_QUADS, 0, 4 );
glPopAttrib();
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
//Set the viewport back to the window size
glViewport(0, 0, 800, 600);
Only thing is, these seems like a MAJOR hack. Is this the official or an acceptable solution?
The best way to do that is to scale the vertices you are drawing to the current viewport size.
For example, to draw a 10px by 10px box(Ignore obsolete api).
You could do it in a shader or on the CPU.
Changing the viewport looks like yet another of those expensive OpenGL state changes.
NOTE:
This could become more complicated with a more complex projection matrix.(I assume the default -1 to 1)