我的OpenGL位图程序崩溃了?

6
我正在使用OpenGL和位图库http://partow.net/programming/bitmap/编写程序,以在屏幕上加载位图。我成功地在屏幕上加载了位图,但是当我尝试使用GetCursorPos中的p.x和p.y将图像加载到光标位置时,应用程序会崩溃。 以下是我的代码:
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++。

谢谢!


1
你已经在这个函数外设置好了OpenGL上下文了吗?https://open.gl/context - Robert Rouhani
1个回答

0

1
我已经完成了这个,只是它在另一个文件中。但还是谢谢你的帮助! - wdt12

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