Texture Questions

Started by
6 comments, last by sprite_hound 16 years, 6 months ago
I am trying to simulate 2d in opengl and I was wondering how I can have a texture that arnt powers of 2 in size or square. For example, I need a texture for the size of the screen. Also, how does the texture datatype work so that I can have direct access to the texture data to modify a single pixel and such? Thanks!
Advertisement
1. textures that are not a power of 2 can be used with the GL_TEXTURE_RECTANGLE_ARB extension

2.
Imagine you have your texture data type set to GL_RGB.
Then you have an array of unsigned char's:
unsigned char pTextureData[width * height * 3]
In this array you can store 24 bit of color information for every pixel.
The first 8 bits are the red ones, the second 8 bits are the green ones and the last are the blue ones.
Then you would use glTexImage2D to set this as the texture data.

hth
Thanks a lot, especially with the first question!

Now, to simulate 2d, which would be faster: Have a single quad that represents the screen and any "blitting" would be done directly to that quad's texture? Or have multiple quads with its own texture?

Thanks!
Quote:Original post by Falling Sky
Now, to simulate 2d...

There's no need to "simulate" 2D in OpenGL, as the Forum FAQ says:
Quote:Can I do 2D in OpenGL?

Yes. Using an orthogonal projection. You can use glOrtho for this. A more detailed answer to the question was posted by Dwarf with Axe here.

This is the standard method for rendering entire 2D applications/games, as well as the 2D parts of 3D applications/games, like a HUD or menu system.

[Edit: FAQ's link is borked.]

[Edited by - jouley on October 1, 2007 2:09:46 PM]
Correct, I am using Ortho!
But I still have to simulate 2d since Ortho is just a means of representing a 3d object in 2d!

Perhaps I should say im trying to simulate direct video access where you manipulate the screen as opposed to creating a quad and texturing them.

So, does anyone have an answer to the question in my previous post?

Quote:Original post by Falling Sky
Correct, I am using Ortho!
But I still have to simulate 2d since Ortho is just a means of representing a 3d object in 2d!
Likewise, a perspective projection is also a means of representing a 3D object in 2D.

Quote:Perhaps I should say im trying to simulate direct video access where you manipulate the screen as opposed to creating a quad and texturing them.

There's nothing that says you have to texture quads using an orthographic projection. In fact, to "simulate direct video access" and operate pixel by pixel, simply map your orthographic projection to the screen's width and height:
glOrtho(0, screenX, 0, screenY, -1, 1);...glBegin(GL_POINTS);glVertex2i(0,0);  // bottom left pixelglVertex2i(1,0);  // adjacent to the right...glEnd( );

If that's still not what you're looking for, perhaps give us an example of exactly what you're trying to do, via illustration, pseudocode, etc.
I am basically writing a wrapper over opengl. Kind of like how SDL works. Here is an example of how im planning my library to look when in use:
surface* screenPtr = SetupScreen(1024,768,32,1,1,0,1);surface img = LoadBMP("foo.bmp");BlitSurface(img,screenPtr,300,500);UpdateScreen();


Basically my wrapper is just going to hide the opengl code and then encapsulate the quad/texturing process in the data type surface.

I just dont know if im going to have a quad for each surface or if im going to have a single quad and a single texture and modify that texture when the screen is blitted to.
Quote:Original post by Falling Sky
I am basically writing a wrapper over opengl. Kind of like how SDL works. Here is an example of how im planning my library to look when in use:
surface* screenPtr = SetupScreen(1024,768,32,1,1,0,1);surface img = LoadBMP("foo.bmp");BlitSurface(img,screenPtr,300,500);UpdateScreen();


Basically my wrapper is just going to hide the opengl code and then encapsulate the quad/texturing process in the data type surface.

I just dont know if im going to have a quad for each surface or if im going to have a single quad and a single texture and modify that texture when the screen is blitted to.


With OpenGL you probably wouldn't want to be "blitting" from one texture to another. You just render the quads in the right place and in the right order. It seems to me as though you're trying to force an SDL-like interface on OpenGL which isn't likely to give you good results.

So you might want something more like:
// Set up the OpenGL context.SetupScreen(1024, 768, 32);// Load the image to the surface class// loadBMP function contained in your surface class // (there are many other ways you might do this though).surface img;img.loadBMP("img.bmp");// rendering function also contained in your surface class// will set the appropriate texture and send vertices / texture coords.img.render(300, 500);


To answer your question then: a quad for each surface.

This topic is closed to new replies.

Advertisement