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

c – OpenGL位图程序只显示白色,黑色和黄色?,第1张

概述我在 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, 我在 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 bitmapunsigned 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,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,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.}

关于什么是错的任何想法?
谢谢!

解决方法 红色,绿色,蓝色的颜色值为unsigned char类型,范围为0..255. glcolor的浮点变量glcolor3f但是要求输入值在0..1范围内.尝试使用glcolor3ub()代替.

更新:我的原始答案建议glcolor3b()但它应该是无符号变量glcolor3ub().

总结

以上是内存溢出为你收集整理的c – OpenGL位图程序只显示白色,黑色和黄色?全部内容,希望文章能够帮你解决c – OpenGL位图程序只显示白色,黑色和黄色?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1227862.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存