OpenGL显示2D图片的问题,高分紧急请教!

smile_wu 2005-05-13 02:43:50
我现在遇到的问题是
1 OpenGL显示2D图片时,其效果是否能够达到原图效果?(我试过网上的代码,256*256大小的图片,显示不能达到原图效果.)
2 是否显示的图片宽度和高度必须是2的幂,显示的效果才好一点,其他如5*5,35*40,效果会更差?
3 如何解决以上出现的问题,显示时能够达到原图效果? 请给出一些建议或者资料代码等.
我是初学者,对以上的问题十分疑惑,望高手能够解答,不胜感激涕零.
...全文
1133 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
summer54 2005-05-17
  • 打赏
  • 举报
回复
Mipmapping! You may have noticed that when you make an image very tiny on the screen, alot of the fine details disappear. Patterns that used to look nice start looking real bad. When you tell OpenGL to build a mipmapped texture OpenGL tries to build different sized high quality textures. When you draw a mipmapped texture to the screen OpenGL will select the BEST looking texture from the ones it built (texture with the most detail) and draw it to the screen instead of resizing the original image (which causes detail loss).
there was a way around the 64,128,256,etc limit that OpenGL puts on texture width and height. gluBuild2DMipmaps is it. From what I've found, you can use any bitmap image you want (any width and height) when building mipmapped textures. OpenGL will automatically size it to the proper width and height.

// Create MipMapped Texture
glBindTexture(GL_TEXTURE_2D, texture[2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
CGChina 2005-05-16
  • 打赏
  • 举报
回复
DrawPixels就行了。只是慢了一点。
IO_X 2005-05-16
  • 打赏
  • 举报
回复
OpenGL可以直接二维操作,gl**2*的某些函数都是二维光栅操作,显示图像规格也不用2次幂,显示范围就是原图规格
参考下面函数:
WINGDIAPI void APIENTRY glRasterPos2d (GLdouble x, GLdouble y);
WINGDIAPI void APIENTRY glBitmap (GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap);
寻开心 2005-05-16
  • 打赏
  • 举报
回复
3d表现出来的物体的效果和原图不同,另外还有一个原因是光照的问题
原图当作纹理使用,在3d环境当中显示出来的时候,图片的亮度收到承载它的三角形的顶点的光照强度影响,会使得不同部分的光照强度不同,和原图相比自然就会有明暗的变化了。

细节上的变化是mipmap等级选择的问题
chglei1976 2005-05-14
  • 打赏
  • 举报
回复
使用平行投影方式,使取景体的宽高和图片大小相匹配。
chunhai12 2005-05-14
  • 打赏
  • 举报
回复
那样就应该是happy__888所说的mipmap的设置问题
smile_wu 2005-05-13
  • 打赏
  • 举报
回复
原图效果 是指 : 我把原始图片加载到程序里面用OpenGl显示处理后就和原始图片相差一些了,有了效果上的损失.
chunhai12 2005-05-13
  • 打赏
  • 举报
回复
楼主说的原图效果是什么意思
寻开心 2005-05-13
  • 打赏
  • 举报
回复
3d的就是3d的,虽然它可以通过投影的方式来模拟2d的,但是本身依然是3d的处理模式

图形效果:那是纹理滤波方式,mipmap的设置问题
图片规格:2的幂不是必须的

这两个问题在论坛当中多次被问及,搜索即可

8,304

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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