急助:谁能提供opengl中载入图片生成纹理的程序

jhlan 2007-08-23 07:52:48
RT!谢谢 尽量简单的,我自己也有,但涉及许多库里不常见的函数,标识符,很难



还一个问提:olectl.h这个头文件里放了些什么东东?

谢谢!!!!!
...全文
704 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
kkun_3yue3 2007-08-29
  • 打赏
  • 举报
回复
//载入纹理图片
AUX_RGBImageRec *oImage::LoadBMP(char *filename)
{
FILE *file = NULL;
if(!filename)
return NULL;
file = fopen(filename,"r");
if(file)
return auxDIBImageLoad(filename);
return NULL;
}

//创建纹理
bool oImage::LoadT8(char *filename, GLuint &texture)
{
AUX_RGBImageRec *pImage = NULL;
pImage = auxDIBImageLoad(filename);
if(pImage == NULL) return false;
glGenTextures(1, &texture);
glBindTexture (GL_TEXTURE_2D,texture);
gluBuild2DMipmaps(GL_TEXTURE_2D,4, pImage->sizeX,
pImage->sizeY,GL_RGB, GL_UNSIGNED_BYTE,pImage->data);
free(pImage->data);
free(pImage);
return true;
}

//绑定并设置纹理显示参数
void oImage::Inittexture(UINT textur)
{
glBindTexture (GL_TEXTURE_2D, textur);
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_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
}
robertcarlos 2007-08-28
  • 打赏
  • 举报
回复
马超的能说明问题了。
qianlima888 2007-08-24
  • 打赏
  • 举报
回复
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>

#pragma comment (lib,"OpenGL32.lib")
#pragma comment (lib,"GLu32.lib")
#pragma comment (lib,"GLaux.lib")

GLuint texture[1];
qianlima888 2007-08-24
  • 打赏
  • 举报
回复
int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indica
AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL
// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if (TextureImage[0]=LoadBMP("******.bmp"))
{
Status=TRUE; // Set The Status To TRUE
glGenTextures(1, &texture[0]); // Create The Texture
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[0]);

// Generate The Texture
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
}

if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
free(TextureImage[0]->data); // Free The Texture Image Memory
}

free(TextureImage[0]); // Free The Image Structure
}
return Status; // Return The Status
}


AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
{
FILE *File=NULL; // File Handle

if (!Filename) // Make Sure A Filename Was Given
{
return NULL; // If Not Return NULL
}

File=fopen(Filename,"r"); // Check To See If The File Exists
if (File) // Does The File Exist?
{
fclose(File); // Close The Handle
return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
}

return NULL; // If Load Failed Return NULL
}


glBindTexture(GL_TEXTURE_2D, texture[0]);

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧