OpenGL texture, doesn't like my bmp - opengl

don't worry, I don't want to ask how to use textures. :)
My problem is:
I'm using several textures. But if I want to change the file name like this:
(LoadBMP("grass.bmp", textureImage[3])) // I can see the grass
to
(LoadBMP("parkett.bmp", textureImage[3])) // No texture, only white color
Both pictures are in the same directory and there is no error message.
Any ideas?
Thanks
Sonja
(OpenGL, Visual Studio C++ 2010)

Most likely, those textures use a different format (.bmp is not just a single format) and your function only supports one.
The simplest and best solution is to use a good library to load your textures, instead of some mystical LoadBMP. I recommend SOIL - Simple OpenGL Image Loader. Just add it to your project and you'll be able to load any bmp, jpg or png textures to an OpenGL texture ID with a single function call.

Can just assume your second BMP has wrong internal data format (non-BGR or something like that). Agreed with Kos - you should try using some libraries for this purpose. There are lots of 'em - SFML, SDL_image, DevIL...

Are the dimensions of the non-working texture powers of 2 (i.e. 1, 2, 4, 8, 16, 32, ...)? If not, then that's why it's not working. Either scale or pad.

Related

Is there any equivalent for gluScaleImage function?

I am trying to load a texture with non-power-of-two (NPOT) sizes in my application which uses OGLPlus library. So, I use images::Image to load an image as a texture. When I call Context::Bound function to set the texture, it throws an exception. When the size of the input image is POT, it works fine.
I checked the source code of OGLPlus and it seems that it uses glTexImage2D function. I know that I can use gluScaleImage to scale my input image, but it is dated and I want to avoid it. Is there any functions in newer libraries like GLEW or OGLPLUS with the same functionality?
It has been 13 years (OpenGL 2.0) since the restriction of power-of-two on texture sizes was lifted. Just load the texture with glTexImage and, if needed, generate the mipmaps with glGenerateMipmap.
EDIT: If you truly want to scale the image prior to uploading to an OpenGL texture, I can recommend stb_image_resize.h — a one-file public domain library that does that for you.

OpenGL VBO Loading Font data

I need to draw a VBO consisting of font data, mainly numbers. How do I obtain the data and send it to the VBO?
I know that there is a library called freetype which should do this, but that uses bitmap fonts and I do not need bitmaps in my project. I just want polygon data which I can fill with my own color and reposition/scale.
Freetype also does outline fonts, but how do I go about tessellating the outline fonts to create accurate geometry?
Is what I am trying to achieve difficult? Can I find some examples of something similar?
Is what I am trying to achieve difficult?
In the case of rendering crisp fonts at all sizes with proper gamma correction and antialiasing: Yes!
This is actually a subject of active research.
Can I find some examples of something similar?
Just use a ready to use font drawing library for OpenGL, like FTGL.
A solution that could work is to save the font data as XY coordinates with indices from a 3D Modeling program. Than this data is loaded at startup, the result being the desired one.
Of course that this does not work when changing fonts and it takes time, but if the font will not change, it does its job.

Texture Mapping C++ OpenGL

I have read around on this, including Nehe and here for solutions, but I cant find a specific answer.
I am trying to load a a photo, called stars.jpg. I want to make this my background of the scene, by mapping it using uv coordinates, doing it by
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(0,0);
However I am just very confused about how to load the actual textures in, all the calls for
glActiveTexture();
glEnable(GL_TEXTURE_2d);
glBindTexture(GL_TEXTURE);
All they do is confuse me, what do all these mean/do, and in what order am I suppose to put these in, in order to get the stars.jpg to be my background?
Your number-one tool for loading textures in OpenGL is the Simple OpenGL Image Loader (SOIL) library. You just need to pass the filename and some flags and you'll get your texture ID.
Also, you're learning very old and outdated version of OpenGL now - you might want to have a google for newer tutorials or browse the specs whenever you feel ready.
Here's a step by step tutorial on loading textures
http://www.nullterminator.net/gltexture.html
Its important to remember that OpenGL is a state machine, so you have to tell it "I'm going to talk about textures now" that's where the glActiveTexture(); comes in.
Also keep in mind that you will have to load in pixel by pixel the colors from your .jpg (compressed) to your texture array, so either you will need to find a library that will give you bitmap values of your .jpg file or you will need to pre-convert it into a .ppm or a .bmp which will make reading in the values easier.

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.

C++ Spin Image Resources

Does anyone know of a good resource that will show me how to load an image with C++ and spin it?
What I mean by spin is to do an actual animation of the image rotating and not physically rotating the image and saving it.
If I am not clear on what I am asking, please ask for clarification before downvoting.
Thanks
I would definitely default to OpenGL for this type of task, you can load the image into a Texture, then either redraw the image at different angles, or better yet you can just spin the 'camera' in the OpenGL engine. There are loads of OpenGL tutorials around, a quick google search will get you everything you need.
You could use SDL and the extension sdl_image and/or sdl_gfx
In Windows using GDI+ you could show rotated image in the following way:
Graphics graphics( GetSafeHwnd() ); // initialize from window handle
// You can construct Image objects from a variety of
// file types including BMP, ICON, GIF, JPEG, Exif, PNG, TIFF, WMF, and EMF.
Image image( L"someimage.bmp" );
graphics.RotateTransform( 30.0f ); // 30 - angle, in degrees.
graphics.DrawImage( &image, 0, 0 ); // draw rotated image
You could read here more detailed explanation.
Second solution is to use DirectX. You could create texture from file and later render it. It is not trivial solution, but it'll use hardware acceleration and will give you the best performance.
On Windows 7 there is available new API called Direct2D. I have not used it yet, but it looks promising.
Direct2D provides Win32 developers with the ability to perform 2-D graphics rendering tasks with superior performance and visual quality.
i agree with DeusAduro. OpenGL is a good way of doing this.
you can also do this with Qt
The "roll-your-own" solution is difficult.
I'd suggest looking into WPF - it might have some nice options in an image control.