1

Does OpenGL have a simple function that loads texture from a resource file, so I could get rid of (HBITMAP)LoadImage(); function that I use instead.

As an example in DirectX it can be done by D3DXCreateTextureFromResourceA(); function.

  • 2
    OpenGL has nothing to do with asset loading. It only knows to draw pixels. That's it.You must use external libs to load your assets into memory. – Michael IV Feb 11 '14 at 15:10
  • @MichaelIV: That being said it's perfectly possible to implement asset from resource loading. In fact in my earliest OpenGL programs I actually did this (the code is horrible though). – datenwolf Feb 11 '14 at 17:50
  • @datenwolf of course!,but many people new to OpenGL mistakenly assume the API provides assets loading features. – Michael IV Feb 11 '14 at 19:43

1 Answers1

0

Use Qt, you will find it's easy to write code with OpenGL.

You can load a lot of image with different formats.

QString fileName = QFileDialog::getOpenFileName(this, "open image file", ".", "Image files (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *.xbm *.xpm);;All files (*.*)");
QImage image;

image.load(fileName);

Also, it is easy to change normal image to OpenGL texture.

QImage textureImage = QGLWidget::convertToGLFormat(image);
GLuint glTexture;

glGenTextures(1, &glTexture);
glBindTexture(GL_TEXTURE_2D, glTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureImage.bits());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
wxfred
  • 1
  • 4