[英]Does OpenGL have a function that loads texture from a resource?
Does OpenGL have a simple function that loads texture from a resource file, so I could get rid of (HBITMAP)LoadImage();
OpenGL是否具有从资源文件加载纹理的简单函数,所以我可以摆脱
(HBITMAP)LoadImage();
function that I use instead. 我使用的功能。
As an example in DirectX it can be done by D3DXCreateTextureFromResourceA();
作为DirectX中的示例,可以通过
D3DXCreateTextureFromResourceA();
完成D3DXCreateTextureFromResourceA();
function. 功能。
Use Qt, you will find it's easy to write code with OpenGL. 使用Qt,您会发现使用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. 同样,很容易将普通图像更改为OpenGL纹理。
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.