Skip to main content
GameDev.net gamedev.net
🔒 Locked

OpenGL Extension

Started by frankmail007 Jun 26, 2006 at 3:01 AM 15 replies 4.3k views
Original Post
frankmail007
frankmail007
I'm new to OpenGL. I have a simple question regarding with OpenGL Extension. As a common knowledge I know the opengl can only support bitmap's width and heigth in power of 2. It's a very nasty problem. How can I overcome this problem? I know there is a extension called GL_ARB_texture_non_power_of_two. The question is how I can use it. I'm trying to use Glew to check. Unfortunately it seems it can't be support in my pc. What's wrong with it? Should I install something?
frank
Enrico
Enrico
Make sure you have the latest drivers installed for your card (which card do you have btw.?). If you then don't have support for this extension, try ARB_texture_rectangle: It is similar to ARB_NPOT, but without filtering/mipmaps (not sure right now). If this extension is unsupported or you require filtering/mipmaps, you should go with the glu*-functions (gluBuildMipmaps2D() especially). This function will take your texture data and fit it into a POT texture, so you can use filtering and mipmapping easily. The remaining space is filled zero bytes, so it is wasted. You may want to take care of this.
--
Charon
Charon
Actually you graphics-adapter might not support non-power-of-two textures, only newer ones do so. Depending on how old your drivers for your graphics-adapter are these might not have support for non-power-of-two textures too.

So first thing you should do is update your drivers.

Then please check for the following extensions (just test with GLEW) :
- GL_NV_texture_rectangle
- GL_ARB_texture_rectangle
- GL_EXT_texture_rectangle

Everyone of these indicates that your graphics-adapter supports non-power-of-two textures. If your graphics-adapter supports none of these you'll have to get a new one :-(

And no there is nothing you can install that magically enables non-power-of-two textures for you. (don't even ask about MESA, thats only software-rendering).

regards
Markus

PS.: just tell us which graphics-adapter you have and we most propably can tell you what you need to know!
chaos, panic and disorder - my work here is finished
Charon
Charon
@Enrico :

from here http://www.mevis.de/opengl/gluBuild2DMipmaps.html

gluBuild2DMipmaps obtains the input image and generates all mipmap images (using gluScaleImage) so that the input image can be used as a mipmapped texture image. glTexImage2D is then called to load each of the images. If the dimensions of the input image are not powers of two, then the image is scaled so that both the width and height are powers of two before the mipmaps are generated.
chaos, panic and disorder - my work here is finished
frankmail007
frankmail007
My VGA card is ATI Mobility Radeon 9700. I think it's not very old, right?

Since this extension is not supported by most of the VGA card, I'm afraid I can't use it. I'm writing a simple game. It should have a low requirement for hardware. Maybe I should try gluBuild2DMipmaps.

Thanks for your replys.
frank
Gyrbo
Gyrbo
GL_ARB_texture_rectangle should be support from Geforce2/Radeon 7000, according to the OpenGL Extension Viewer. Make sure you have the latest drivers installed.
MARS_999
MARS_999
Quote:
Original post by frankmail007
My VGA card is ATI Mobility Radeon 9700. I think it's not very old, right?

Since this extension is not supported by most of the VGA card, I'm afraid I can't use it. I'm writing a simple game. It should have a low requirement for hardware. Maybe I should try gluBuild2DMipmaps.

Thanks for your replys.


No on the 9700 only the x1000 series and I am not sure all of them support NPOT, but on Geforce6/7 series they do. You can either look into arb_texture_rectangle or use gluBuild2DMipmaps() this will rescale your image to POT for you. Better yet just use PS or some image program and scale it yourself and upload it as POT... And if you go the arb_texture_rectangle route there are some issues you need to be aware of. So instead of thinking of the texture image lying in a [0..1]x[0..1] range, the NPOTS texture image lies in a [0..w]x[0..h] range.
frankmail007
frankmail007
Quote:
Original post by MARS_999

No on the 9700 only the x1000 series and I am not sure all of them support NPOT, but on Geforce6/7 series they do. You can either look into arb_texture_rectangle or use gluBuild2DMipmaps() this will rescale your image to POT for you. Better yet just use PS or some image program and scale it yourself and upload it as POT... And if you go the arb_texture_rectangle route there are some issues you need to be aware of. So instead of thinking of the texture image lying in a [0..1]x[0..1] range, the NPOTS texture image lies in a [0..w]x[0..h] range.


Does arb_texture_rectangle support most of the vga card?

If I have a window size 800x600 and I want to show my texture as background in that window, is gluBuild2DMipmaps possible to do that or it just scales the image to 1024x1024 and show only part of the image on that window?
frank
deavik
deavik
Quote:
Original post by frankmail007
If I have a window size 800x600 and I want to show my texture as background in that window, is gluBuild2DMipmaps possible to do that or it just scales the image to 1024x1024 and show only part of the image on that window?

The best thing to do would be to resize the 800x600 image to 1024x1024 in an art program, touch up as required, and use it to texture a screen aligned 800x600 quad in your program.

While ARB_texture_rectangle is really convenient in some cases (notably where the NPOT texture is dynamically generated) - I think in your case you should consider using a POT texture. Also, as others have mentioned, texture_rectangle has some pretty serious limitations.

Just my opinion. [smile]
frankmail007
frankmail007
What you mean is to resize my 800x600 to 1024x1024 then scale it to 800x600 texture?

I'm using the following function:

glTexImage2D( GL_TEXTURE_2D, 0, bpp, texW, texH, 0,
format, GL_UNSIGNED_BYTE, m_pImage->getPixels() );

How can I scale it to 800x600 since the texW and texH will be 1024 already?

Sorry for my stupid question. I'm very new to OpenGL.
frank
MARS_999
MARS_999
If you are loading a 800 x 600 texture then do this

gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB8, width, height, GL_RGB, GL_UNSIGNED_BYTE, imageData);

this will load your texture data correctly and allow GL to display it on your back ground. No need for extensions this way. Now if you are doing RTT then you will need to use arb_texture_rectangle or arb_texture_NPOT.
HTH
davepermen
davepermen
Quote:
Original post by MARS_999
If you are loading a 800 x 600 texture then do this

*** Source Snippet Removed ***
this will load your texture data correctly and allow GL to display it on your back ground. No need for extensions this way. Now if you are doing RTT then you will need to use arb_texture_rectangle or arb_texture_NPOT.
HTH


that way it will be blurred as it will result in eighter a 1024x1024 texture, or a 512x512 texture (unsure wich one), and generate the according mipmaps below. thus rendering that texture will result in filtering and blurring.
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
deavik
deavik
Quote:
Original post by frankmail007
What you mean is to resize my 800x600 to 1024x1024 then scale it to 800x600 texture?

I'm using the following function:

glTexImage2D( GL_TEXTURE_2D, 0, bpp, texW, texH, 0,
format, GL_UNSIGNED_BYTE, m_pImage->getPixels() );

How can I scale it to 800x600 since the texW and texH will be 1024 already?

Sorry for my stupid question. I'm very new to OpenGL.

What I mean is this:

1. Resize image to 1024x1024 in art program.

2. Load as texture in OPenGL:
glTexImage2D(GL_TEXTURE_2D, 0, bpp, 1024, 1024, 0, format, GL_UNSIGNED_BYTE, m_pImage->getPixels());

2. Set up Ortho mode:
glOrtho(0, 800, 0, 600);

3. Draw quad to cover screen:
glBindTexture(GL_TEXTURE_2D, your_1024x1024_texture_id);glEnable(GL_TEXTURE_2D);glBegin(GL_QUADS);glTexCoord2f(0, 0); glVertex3f(0, 0, 0);glTexCoord2f(1, 0); glVertex3f(800, 0, 0);glTexCoord2f(1, 1); glVertex3f(800, 600, 0);glTexCoord2f(0, 1); glVertex3f(0, 600, 0);glEnd();


You get the idea [smile]!
MARS_999
MARS_999
Quote:
Original post by davepermen
Quote:
Original post by MARS_999
If you are loading a 800 x 600 texture then do this

*** Source Snippet Removed ***
this will load your texture data correctly and allow GL to display it on your back ground. No need for extensions this way. Now if you are doing RTT then you will need to use arb_texture_rectangle or arb_texture_NPOT.
HTH


that way it will be blurred as it will result in eighter a 1024x1024 texture, or a 512x512 texture (unsure wich one), and generate the according mipmaps below. thus rendering that texture will result in filtering and blurring.


Yes, most likely it will, but he doesn't have NPOT support and seems to not want to resize his texture in Photoshop and upload it as a POT so his only options left are gluBuild2DMipmaps or arb_texture_rectangle and the rectangle has its own issues, but for a simple fix thats probably good enough for now I suggested gluBuild2DMipmaps. :) But yeah I agree the image will most likely be degraded.
Charon
Charon
another possibility would be to use a 1024*1024 texture, but only use 800*600 pixels of it.

create a 1024*1024 image, insert your 800*600 image into it and align it with the upper left corner. let the rest of the image be black for example.

if i am not completely wrong you would use it this way :
glBindTexture(GL_TEXTURE_2D, your_1024x1024_texture_id);glEnable(GL_TEXTURE_2D);glBegin(GL_QUADS);glTexCoord2f( 0, 0 ); glVertex3f(0, 0, 0);glTexCoord2f( 1/1024*800, 0 ); glVertex3f(800, 0, 0);glTexCoord2f( 1/1024*800, 1/1024*600 ); glVertex3f(800, 600, 0);glTexCoord2f( 0, 1/1024*600 ); glVertex3f(0, 600, 0);glEnd();


yes you are wasting precious texture-memory with this technique.
the only benefit it has is that you can just upload your image with glTexImage2D and don't have to fear that gluBuild2DMipmaps downscales your image when it tries to fit it into a texture.
chaos, panic and disorder - my work here is finished
frankmail007
frankmail007
Thanks for all your advice. I'll try it.
frank
pauljan
pauljan
I take it you just want to map that texture on a quad in the background and show that with 1:1 pixel accuracy anyway?

Personally, I'd write a routine to chop up an image into smaller textures mapped onto individual rectangles, using the closest power of 2 numbers you can get (with some threshold). In this case, that would imply chopping the 800x600 image into a 512 + 256 + 32 by 512 + 64 + 16 + 8 image. Or 512 + 64 + 32 if you want to draw the line at individual 32x32 textures.

A bit tricky to set up correctly, but in general those extra polygons are cheaper than wasted texture memory. It depends very much on your specific application.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.