【问题标题】:My OpenGL bitmap program is crashing?我的 OpenGL 位图程序崩溃了?
【发布时间】:2016-01-18 04:21:31
【问题描述】:

我正在使用 OpenGL 和http://partow.net/programming/bitmap/ 的位图库让程序在我的屏幕上加载位图。我已经在我的屏幕上加载了位图,但是当我尝试使用 p.x 和 p.y(来自 GetCursorPos)在光标位置加载图像时,应用程序崩溃了。 这是我的代码:

void Image(HDC hDC, string File_Name, int x_position, int y_position, int length, int height)      // Image()
{
File_Name = "C:/Users/David/Pictures/" + File_Name + ".bmp";      // add a full path to the file name
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.
glColor3ub (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);
glColor3ub (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         
}



int main()               // int main()
{
POINT p;
if(GetCursorPos(&p))
{
Image(hDC, "Image", p.x, p.y, 1340, 678);
}
}

我在 Windows 7 上使用 Dev C++。 谢谢!

【问题讨论】:

  • 您是否已经在此函数之外设置了 OpenGL 上下文? open.gl/context

标签: c++ opengl bitmap


【解决方案1】:

您还需要设置 OpenGL 上下文才能使其正常工作。看这个:https://www.opengl.org/wiki/Creating_an_OpenGL_Context_(WGL)

【讨论】:

  • 我已经这样做了,我只是将它放在另一个文件中。但是感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多