C++ 你如何在 OpenGL 中显示图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7006213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you display images in OpenGL
提问by viraj
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.
您如何使用 OpenGL 渲染图像(.bmp 和 .jpeg)?我遇到过一些教程,但它们是针对 C# 而不是 C/C++ 的。我想渲染图像的原因是因为我想画一艘宇宙飞船(用于游戏)。我可以使用 OpenGL 原语,但它看起来并不是那么好。另一种选择是使用坐标绘制宇宙飞船,但这需要很长时间,而且看起来不会那么好。
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
我究竟做错了什么 ?代码写得不好。对于那个很抱歉。现在工作
采纳答案by ssell
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.
除非您真的需要.bmp
或.jpeg
,否则我建议您使用.tga
(Targa) 图像,因为它们更常用并且支持 alpha 通道。
Some C++ resources:
一些 C++ 资源:
http://nehe.gamedev.net/tutorial/loading_compressed_and_uncompressed_tgas/22001/
http://nehe.gamedev.net/tutorial/loading_compressed_and_uncompressed_tgas/22001/
http://nehe.gamedev.net/tutorial/texture_mapping/12038/
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.)
http://www.lonesock.net/soil.html(一个很棒的 OpenGL 小图像库。支持 bmp、jpg、png、tga 等)
回答by B?ови?
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.
类似地震的游戏将人类渲染成侧面具有不同纹理的立方体。你也可以这样做。启用 alpha 混合并确保透明纹理数据是真正透明的。
回答by SurvivalMachine
Render a textured quad or two triangles that form a rectangle.
渲染一个带纹理的四边形或两个三角形,形成一个矩形。