Read .tga with DirectX 11 - c++

Since a few days im working on a tool where i need to draw textures on several file format with directX 11. After googling a lot, i didnt found how to do.
I'm using D3DX11CreateShaderResourceViewFromFile for load .dds and .png files, but i read somewhere else that .tga isn't supported anymore. I read something too about D3DLOCKED_RECT to set each pixels of the texture, and read .tga files to know these pixels, but that was for directX 9.
Any help or tips? Thanks in advance.

//note: I don't use D3D11
MSDN page for D3DX11CreateShaderResourceViewFromFile says there is DirectXTex library, that should be able to load *.tga files using LoadFromTGAFile routine. You should give it a try. If it doesn't work for you, you'll have to write your own texture loader. (because it was possible to make your loader for textures in D3D9, it should be possible to do the same thing in D3D11). *.tga format is documented somewhere and many beginner tutorials specifically deal with loading this particular format without 3rd party libraries.
Two advices:
Next time, when in doubt, read documentation.
DON'T look at *.png format. This format loads very slowly (jpeg is faster, uncompressed bmp is faster, dds is faster) and most likely isn't suitable for games that need to load many images often (it is okay to use it for start menu, ending screen, etc). Either use uncompressed format (such as *.tga) or (since you're using directx) use *.dds format. Your images most likely will take extra disk space, but will load more quickly.

Related

OpenGL, extract "sprites" from .pzx and .mpl in GLS_BINARY_LSB_FIRST format

I'm seeking help in extracting sprites from an old file type.
The sprites are stored in this >>GLS_BINARY_LSB_FIRST<< format in .pzx files, alongside with some other .mpl files.
They seem to be in some kind of OpenGL format, although I did not find any information about their structure.
The only system capable of "handling" these files is an old IRIX64, which I tried in an emulator but didn't worked.
My Question is if it's possible to extract the data from them to possibly OpenGL Textures that I could then write to sprites?
Best regards!
I uploaded a sample 001.mpl and 001.pzx here:
Link

Using OpenGL to write to an image file

I'm just curious if there is a way to use OpenGL to write pixel data to an external JPEG/PNG/some other image file type (and also create an image to write the data to if one does not already exist). I couldn't really find anything on the subject. My program doesn't really make use of openGL at all otherwise, I just need something that can write out images.
Every image "put into" or "taken from" OpenGL is in a rather raw pixel format. OpenGL does neither have functionality for file I/O nor for handling of sophisticated image formats like e.g. BMP, JPEG or PNG, as that is completely out of its scope. So you will have to look for a different library to manage that and if this was the only reason you considered OpenGL, then you don't need it at all.
A very simple and easy to use one (and with an interface similar to OpenGL) would be DevIL. But many other larger frameworks for more complex tasks, like Qt (GUI and OS) or OpenCV (image processing) have functionality for image loading and saving. And last but not least many of the individual formats, like JPEG or PNG usually also have small official open-source libraries for handling their respective files.

OpenGL ES 2 - load and display image

I'm having trouble finding any examples of OpenGL ES 2 (C++) loading/displaying images. Been looking for last 3 hours but all I found so far is for iPhone or "Look Ma! A triangle!" or it's unbelievably complicated (at least for me).
I'm just looking for something super easy (for a not very smart person). All I need is to load 2 jpg images, display one of them and then display another one in a second or two...
Thanks :)
You didn't specify what platform.
Loading of images is the process of reading a binary file format and possibly decompressing the data. That is not part of the OpenGL or OpenGL-ES spec.
If you want to load and display textures, the easiest way to do it is use some library that already does all the hard work for you. Here are a few resources that show you the library and the roll it your own approach:
Tutorial of loading various image formats using SDL and SDL_image
Load bitmaps in C++ on windows and other desktop platforms
Tutorial loading sprites using Cocos2d
More details on the bitmap file format

Loading PNG textures to OpenGL

I'm working on a game, and all of my graphics use magenta as transparent/magic color.
They are all 32-bit and the magenta is just for conveniency.
Anyway, I would appreciate if someone could advice me what library should I use to load my images (I need to load them in GL_RGBA format, both internal and texture specific).
If only PNG support is necessary, use libpng. DevIL is supposed to be easy, but it's somewhat bloated (does a lot more than just load images) and internally actually calls OpenGL functions which can mess with your own OpenGL logic.
I personally prefer SDL_image, since I'm using SDL in my projects anyway. While not immediately obvious, SDL_BlitSurface() function can do the conversion from whatever IMG_Load() returns to the necessary pixel format.
DevIL can load virtually every file format and can directly create OpenGL textures. It is the easiest way to go.
You should also use a file format which supports an alpha channel (PNG, TGA, ...). Using a "magic color" in 32-bit images is really out-dated!
Apart from the other answers mentioning SDL and DevIL, there are two more options to consider:
Use libpng directly. This will probably have the smallest impact on the code size if that matters, since you get no bloat for other formats you're not using, no DLLs, etc.
Use operating-system texture loading. This can be a nice way to reduce dependencies if you prefer using OS features over external libraries. GDI+ in Windows XP and up has built-in texture loading for a few formats like PNG and JPEG, and I don't know for certain, but other OSs might have similar features. It's pretty simple to hook GDI+ up in to OpenGL and then the OS is taking care of your texture loading!
There is a very minimalist one file example of loading a png into openGL here:
http://tfc.duke.free.fr/coding/src/png.c
Another option is OpenCV.
It does a lot more than just texture loading, but odds are good you'll find use of its other features as well.

Take advantage of Flash CS4's PNG Compression, but as an external file?

Here's the issue: I'm developing some Flash web sites and really enjoying AS3.
The problem: PNG 24-bit images are too big... I have three PNG images with transparency that I'd like to rotate through on the "Home page" every 10 seconds or so. Great. No problem - but instead of embedding all three PNGs in the SWF, which would take the thing longer to load, I'd like to load them dynamically from external files, so that the user doesn't have to wait around for images to load that aren't going to be displayed for another 10-15 seconds anyway. That's fine... I have working code for that.
The real problem: These PNG sizes, even loaded from external files on the fly, are really bugging me. One image is 350k when saved with Photoshop - 300k when I use PNGOUT. But... when I import the PNG into Flash's Library, I can go in and set it to JPG/Image Compression which reduces the size to about 45k, yet maintains the alpha information!! If Flash can compress my PNG that much, and still make it look good, why can't I find an app that can do the same for an external file? I'd be content to load my images into the Flash library and let it handle the compression, but if I end up with 5 or 6 images, that still turns out to be too long of a loading time.
Summary: How can I shrink my 350k PNG image with transparency down to 45k like Flash does when I import it into it's library?
Possible solution: Or.... hmmmm.... this could be a workaround... maybe I could just make a separate SWF movie for each PNG I want to use which uses the Flash compressed image - then read that file dynamically using a Loader... That ought to work! I shall return and report...
But still, how does Flash compress those PNGs so much more than compressors like PNGOUT? Maybe I'm just not passing in the right parameters for them to be effective.
Thanks for reading my ramblings. You all are a great sounding board!
PNG compression is lossless, so it can't compete with lossy perceptual compression schemes as JPEG. Just be sure that your png are the size to be displayed (or not : one trivial "compression" scheme would be to save your image scaled down and zoom it when displaying, but this is normally unsatisfactory). If you can't go below 24-bits (you cant go to a 256-pallete, I guesss) I dont think much can be done. I can only suggest to give a look at PngCrush.
I used to have the same question, but later, I think flash used JPEG compress for PNG files. The JPEG-compressed "png" is actually a variant that standard png format does not support, but flash supports. In my own flash project, I used it a lot. I even used swftools to generate an animated SWF from a lot of png, so I can load the single "png gallery" swf and use all the pngs inside.
I know that the question is a year old, but I thought it would be good for future reference. Using any of the png compression tools (PngCrush, Optipng) will not get anywhere near the same results as Flash compression.
The best way I've found to use flash compression without creating each swf in the Flash IDE is using SwfTools' png2swf utility, it will keep alpha channels and also allow you to set the jpeg's compression quality.
http://www.swftools.org/png2swf.html