费脑!大学生计算机图形学实验报告!
题目:OpenGL下中点画线法绘制三条任意斜率的平行直线
问题:我一直出不来 但是没有报错
以下是代码
```c++
#include <windows.h>
#include <gl/gl.h>
#include <cstdio>
// 函数声明
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void EnableOpenGL(HWND hWnd, HDC *hDC, HGLRC *hRC);
void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC);
void midpointLine(int x0, int y0, int x1, int y1);
// 全局变量
BOOL bQuit = FALSE;
float theta = 0.0f;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
WNDCLASS wc;
HWND hWnd;
HDC hDC;
HGLRC hRC;
MSG msg;
// 注册窗口类
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "GLSample";
RegisterClass(&wc);
// 创建主窗口
hWnd = CreateWindow(
"GLSample", "OpenGL Sample",
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0, 0, 256, 256,
NULL, NULL, hInstance, NULL);
// 启用 OpenGL
EnableOpenGL(hWnd, &hDC, &hRC);
// 程序主循环
while (!bQuit)
{
// 检查消息
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// 处理消息
if (msg.message == WM_QUIT)
{
bQuit = TRUE;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
std::printf("Inside main loop.\n");
// OpenGL 绘制
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
// 设置直线颜色为白色
glColor3f(1.0f, 1.0f, 1.0f);
std::printf("Set line color to white.\n");
// 绘制三条平行直线
midpointLine(50, 50, 150, 150);
midpointLine(50, 55, 150, 155);
midpoin