Archived

This topic is now archived and is closed to further replies.

frmzero2hero

How to texture files which do not have height /width thats a power of 2

Recommended Posts

i want to create texture from a bmp file with resolution 800x600.I I do not want to strech or shrink the resolution ..ie i want to display it as it is. Is there a way to do it?If yes,PLz tell me . note:I am working on Linux for this project. Any help will be appreciated and will be thankful to u all my life

Share this post


Link to post
Share on other sites
Generate mipmaps for that texture with gluBuild2DMipmaps() :

quote:
Red Book, p 385
"If your original has dimensions that are not exact powers of 2, gluBuild*DMipmaps() helpfully scales the image to the nearest power of 2. Also if your texture is too large, gluBuild*DMipmaps reduces the size of the image until it fits".


Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

Share this post


Link to post
Share on other sites
glDrawPixels can render a chunk of memory to the screen, if that''s all you want to do. It will be slow though. But if you want a texture, there is no other way... and don''t dismiss the solution I gave you before even trying it.

As for DirectDraw, it is Windows+DirectX only, hence my comment.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

Share this post


Link to post
Share on other sites
I believe that there''s actually an OpenGL extension you can enable which will allow you to use textures whose heights and/or widths are not powers of two. I''m not sure of it''s name, though. Anyone else know?

You might want to try searching for it here: http://oss.sgi.com/projects/ogl-sample/registry/. This is list of all the OpenGL extensions currently available, maintained by SGI. Have a look through (although there are about 300 of them...sorry )


Movie Quote of the Week:

"You''ve been eating retard sandwiches again."
- Birdman, Beautiful Girls.
Try http://uk.geocities.com/mentalmantle. Seriously. It''s brilliant.
And I just completely redesigned it so it looks even better.
DarkVertex Beta 0.8 available soon!

Share this post


Link to post
Share on other sites
Hey my requirements are very stringent in terms of shrinking/streching because this is being developed for a Physcology experiment and they want to track the exact position of the eye for a picture which is displayed full screen.
I am trying glDrawPixels..but if u have sum code that reads bmp and dumps its pixel info on the screen it will be great

thanks a lot for your Help

Share this post


Link to post
Share on other sites
*sigh* Mipmapping fits the requirements. Which you would realise if you would only read the *censored* manual, or even done a quick search on the concept.

Get your psychology department to buy you a copy if you can't afford it yourself.

As to sharing code, I don't see why I should bother when you're not even doing your share of the research work.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]


[edited by - Fruny on October 3, 2002 3:47:04 PM]

Share this post


Link to post
Share on other sites
Well, glDrawPixels would seem to be the only answer then, if you have to have the exact image you load on the screen.
Mipmapping will distort the image or shrink it (most systems can''t handle textures over 512x512). Either way, you''ll lose pixels...

Look up glReadPixels in the Red Book...


Movie Quote of the Week:

"You''ve been eating retard sandwiches again."
- Birdman, Beautiful Girls.
Try http://uk.geocities.com/mentalmantle. Seriously. It''s brilliant.
And I just completely redesigned it so it looks even better.
DarkVertex Beta 0.8 available soon!

Share this post


Link to post
Share on other sites
hey i have done a lottaq search for mipmapping but it always will change the image ie not give the exact pixel map..
I am not aware of any censored manual...
and furny thanx for u r help .I really appreciate it ..I am on this stuff since a month and i am new to openGL thats y i asked for code.Dont bother as u mentioned

Share this post


Link to post
Share on other sites
quote:
Original post by frmzero2hero I am not aware of any censored manual...


"censored" in his post meant he censored the bad word that went there. i.e. fucking manual

the manual he''s talking about is the openGL red book. there''s an online version of it. search google for openGL red book

-me

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you don''t need texture use DirectDraw or gldrawpixel or something like that...
If you want to use texture (really faster in most cases) then declare a texture bigger than you need (like 1024x1024) and it is just that one part will not be used and you should use coordinate texture between :
800x600 on 1024x1024:
Min x : 0 Max x : 800/1024
Min y : 0 Max y : 600/1024

Use the OpenGL Nvidia extention texture_rectangle_NV but mipmaping will be disabled (of course : you don''t use 2^q x 2^p texture type...)

Share this post


Link to post
Share on other sites
AP is correct
from what ive read (years ago but directdraw hasnt changed since then so i assume its still valid)
directdraw uses the same method ie directdraw only uses power of 2 textures(memory places whatever).
Shock horror
heres an example
create a 1024x1024 texture
stick an image eg (800x600) in a corner
u want another image(120x123) then stick it next to the first image so it goes(800,0)->(920,123)
so basically fill your texture up with smaller (non power of 2 textures)
+ when u draw them just change the texture coordinates.

if this works in directdraw why can i do the same in opengl?

u can BUT u also inherit the limitations on directdraw.
in directdraw u only have NEAREST texture filtering, no LINEAR etc,
using the above method with NEAREST will give correct results if u use any filtering eg LINEAR (or even worse mipmapping) adjacent textures will bleed into each other.

btw the above technique (texture packing) is often used with lightmapping

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
DirectDraw can do non power of 2 off screen surfaces. I suggested DirectDraw as in 2D. Using DirectDraw offscreen surfaces as textures for D3D introduces the power of 2 limit. with DX7 you can mix 2D and 3D. So if your large image is just a background (or doesn''t need any 3D functions like rotation, ect) use an offscreen surface. Then use textures for other things that aren''t as large and oddly shaped.

Older 3D cards max at 256x256 textures but have no problem with large non power of 2 offscreen surfaces.

Ben


IcarusIndie.com [ The Rabbit Hole | The Labyrinth | DevZone | Gang Wars | The Wall | Hosting | Dot Com | GameShot ]

Share this post


Link to post
Share on other sites
glDrawPixel() is SLOW!!! Because you''re sending one pixal at a time to the framebuffer, its much slower than using a texture, but if you''re application doesn''t have a speed requirement when its rendering the image, it will work fine.

The standard is to use a texture and just size you''re window so that logical coordinates are physical coordinates...

You can also break the image up into several 512x512 sections, and render it that way, even if you''ll get extra space offscreen....

Share this post


Link to post
Share on other sites
>>DirectDraw can do non power of 2 off screen surfaces<<

u think its doing non power of 2 sized surfaces cause u say to directdraw give me say (200x345) but in actual fact it is using ^2 sized surface (behind the scenes)

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
Um, hello?

Fruny is trying to help here, and he usually knows exactly what he''s talking about - like in this case!

Use gluBuild2DMipmaps() instead of glTexImage2D() when building your texture, and bang it on a quad with the same aspect ratio as your original texture (ie 4:3) - while gluBuild2DMipmaps() will actually squish the texture to a power of 2 square (I *think*), you''ll find the quality is absolutely fine when rendered onto a 4:3 quad.

If you want the quad to be facing straight towards the viewer then also consider using ortho projection (gluOrtho2D()).

This will be *much* faster than glDrawPixel().

I expect NeHe has tutes on this. Or just look in the forums for "How do I do a splash screen". Not inclined to post code right now.

www.coldcity.com
code, pics, life

Share this post


Link to post
Share on other sites
quote:
Original post by KalvinB
DirectDraw... DirectDraw ..DirectDraw ... D3D ... DX7..



quote:
Original post by frmzero2here
note:I am working on Linux for this project.



RTFQ.


Note to frmzero2hero: sizing up the texture to the nearest power of two when you load it is an easy solution, as someone suggested. Don''t stretch the image, just fill the additional space with black or white. Adjust your texture coordinates so that they match the size of the valid data in the surface, and you''re done.

I actually implemented that straight into my image loader. It always sizes images to powers of 2, since I''m always using them as textures anyway. Sure, I''m throwing out memory by the bucketload, but these are research projects anyway, so it''s not like I need to run them at 150FPS on a 20 Mhz machine.

Share this post


Link to post
Share on other sites
Small point, to everyone who keeps suggesting gluBuild2DMipmaps:

quote:

I do not want to strech or shrink the resolution ..ie i want to display it as it is.



As others have suggested, I would use a 1024x1024 texture with an 800x600 image in the corner. Render it with GL_NEAREST filtering, scaling your tex coords appropriately, and you''re away. The only problem with this is if you''ve got very limited video card memory or if there''s a texture size limit. Decent (ie: not 3dfx) cards shouldn''t have a problem with this.

____________________________________________________________
www.elf-stone.com

Share this post


Link to post
Share on other sites