OpenGL位图程序只显示白色,黑色和黄色?

5

我正在使用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.
}

有什么想法是出了什么问题吗? 谢谢!

请注意,将图像作为纹理上传,然后绘制一个覆盖绘制区域的单个纹理四边形会更有效率。 - Colonel Thirty Two
1个回答

1
颜色值red, green, blue的类型为unsigned char,范围在0..255之间。而glColor的浮点变体glColor3f,期望输入值在0..1的范围内。请尝试使用glColor3ub()代替。
更新:我的原始答案建议使用glColor3b(),但应该使用无符号变量glColor3ub()。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接