Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you display images in OpenGL

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

like image 958
viraj Avatar asked Aug 10 '11 05:08

viraj


3 Answers

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.)

like image 72
ssell Avatar answered Oct 02 '22 11:10

ssell


Render a textured quad or two triangles that form a rectangle.

like image 21
SurvivalMachine Avatar answered Oct 02 '22 13:10

SurvivalMachine


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.

like image 26
BЈовић Avatar answered Oct 02 '22 11:10

BЈовић