How do you render images (.bmp and .jpeg) using OpenGL ? I've come across some tutorials, but they were for C# not C/C++. The reason I want to render images, is because I want to draw a spaceship(for a game). I could use a OpenGL primitive, but it doesn't really look that great. The other option is to draw the spaceship using co-ordinates, but that would take ages, and wouldnt look as good.
running the following snippet always returns failed:
#include <iostream>
#include <GL/glfw.h>
using namespace std;
int main()
{
GLFWimage image;
if(glfwReadImage("ship.tga", &image, GLFW_ORIGIN_UL_BIT)!=GL_TRUE);
cout << "FAILED";
system("PAUSE");
return 0;
}
What am I doing wrong ? Poorly written code. Sorry about that. Works now
By texturing a Quad (or better yet, two Triangles).
Unless you really need .bmp
or .jpeg
, I would suggest that you use .tga
(Targa) images as they are more commonly used and support alpha channel.
Some C++ resources:
http://nehe.gamedev.net/tutorial/loading_compressed_and_uncompressed_tgas/22001/
http://nehe.gamedev.net/tutorial/texture_mapping/12038/
http://www.lonesock.net/soil.html (a great little image library for OpenGL. Supports bmp, jpg, png, tga, etc.)
Render a textured quad or two triangles that form a rectangle.
Quake-like games are rendering humans like cubes with different textures on it's side. You can do that as well. Enable alpha blending and make sure the transparent texture data is really transparent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With