Jump to content
  • Advertisement
Sign in to follow this  
Azh321

OpenGL Texture Questions

This topic is 4040 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

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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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 pixel
glVertex2i(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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

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!