OpenGL位图程序只显示白色,黑色和黄色
OpenGL bitmap program only displaying white, black, and yellow?
我正在使用http://partow.net/programming/bitmap/index.html和OpenGL的库来制作一个函数来加载我屏幕上的位图。图像加载,但它只显示黑色,白色和黄色。我在Windows 7上使用Dev c++。下面是我的代码:
void Load_Image(HDC hDC, string File_Name, int x_position, int y_position, int length, int height)
{
bitmap_image image(File_Name); // Open the bitmap
unsigned char red;
unsigned char green;
unsigned char blue;
restart:
image.get_pixel(x_position, y_position, red, green, blue); // Get the red green and blue from x_position and y_position and store it in red green and blue.
glBegin (GL_TRIANGLES); // Make a pixel at x_position and y_position with red green and blue.
glColor3f (red, green, blue);
glVertex2f (-1 + 0.0015 * x_position, 1 - 0.003 * y_position);
glVertex2f (-1 + 0.0015 * x_position, 0.997 - 0.003 * y_position);
glVertex2f (-0.9985 + 0.0015 * x_position, 1 - 0.003 * y_position);
glEnd();
glBegin (GL_TRIANGLES);
glColor3f (red, green, blue);
glVertex2f (-1 + 0.0015 * x_position, 0.997 - 0.003 * y_position);
glVertex2f (-0.9985 + 0.0015 * x_position, 1 - 0.003 * y_position);
glVertex2f (-0.9985 + 0.0015 * x_position, 0.997 - 0.003 * y_position);
glEnd();
if (x_position==length) // If x_position equals to length of bmp set x_position to 0 and add 1 to y_position.
{
if (y_position==height) // If bmp is done loading go to done.
{
goto done;
}
x_position = 0;
y_position = y_position + 1;
}
x_position = x_position + 1;
goto restart;
done:
SwapBuffers(hDC); // Put it on the screen.
}
有什么问题吗?谢谢!
red
、green
、blue
的颜色值类型为unsigned char
,取值范围为0 ~ 255。glColor
、glColor3f
的浮点变体期望输入值在0..1的范围内。试着用glColor3ub()
代替。
更新:我原来的答案建议glColor3b()
,但它应该是无符号的变体glColor3ub()
。
相关文章:
- 除非重新绘制大小,否则SDL_Texture在调整大小后呈现黑色
- 为什么我会得到黑色纹理?
- 具有 GPU 时间表的卤化物产生黑色图像
- OpenGL只是渲染一个黑色的方块
- 黑色纹理,如果图片大小在第二个 OpenGL 线程中> 1 * 1
- 将未签名的字符转换为红黑色树的签名字符
- CImage::D raw() 画了一幅黑色的图画
- 纹理显示为黑色
- openCV中的Absdiff可以编译,但显示黑色图像
- 在图像上的矩形区域之外填充黑色
- 来自程序子窗口的位图返回为黑色
- 用高斯Seidel红色黑色求解1D泊松方程
- 在 OpenCV 和 C++ 中查找距轮廓中心最近的黑色像素
- 具有SPI_SETDESKWALLPAPER功能的程序仅在尝试使用C++将其更改为图像时将桌面背景更改为黑色
- 现代OpenGL 3.3核心黑色纹理
- 在Android Studio中使用NDK GrabCut返回的OpenCV总是黑色面具
- 如何实现std :: set(红色/黑色树)前迭代
- 带有Clang的DirectX11显示黑色纹理(与Visual Studio配合使用)
- 如何使用opencv将图像中的黄色转换为黑色
- OpenGL位图程序只显示白色,黑色和黄色