gpt4 book ai didi

c++ - OpenGL 位图程序只显示白色、黑色和黄色?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:16:25 24 4
gpt4 key购买 nike

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

有什么问题吗?谢谢!

最佳答案

颜色值 redgreenblue 的类型为 unsigned char,范围为 0。 .255。 glColor 的浮点变体 glColor3f 但是需要 0..1 范围内的输入值。尝试改用 glColor3ub()

更新:我最初的回答建议使用 glColor3b(),但它应该是未签名的变体 glColor3ub()

关于c++ - OpenGL 位图程序只显示白色、黑色和黄色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33190127/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com