#include<windows.h>
#include <gl/GL.h>
#include <gl/GLU.h>
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
void DrawSence()
{
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(10.0f);
glBegin(GL_POINTS);
glColor4ub(200, 0, 0, 255);
glVertex3f(0, 0, -100.0f);
glEnd();
}
//窗口函数声明
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//入口函数 WinMain()
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wndclass; //定义窗口类结构变量
HWND hwnd; //定义窗口句柄
MSG msg; //定义消息结构变量
/********定义窗口类各属性*******/
wndclass.style = CS_HREDRAW | CS_VREDRAW; //改变窗口大小则重画
wndclass.lpfnWndProc = WndProc; //窗口函数为 WndProc
wndclass.cbClsExtra = 0; //窗口类无扩展
wndclass.cbWndExtra = 0; //窗口实例无扩展
wndclass.hInstance = hInstance; //注册窗口类的实例句柄
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); //窗口用默认图标
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); //窗口用箭头光标
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); //背景为白色
wndclass.lpszMenuName = NULL; //窗口默认无菜单
wndclass.lpszClassName = TEXT("FirstWinClass"); //窗口类名为FirstWinClass
/**********************************/
if (!RegisterClass(&wndclass)) return FALSE; //注册窗口类,失败则返回
//创建窗口
/****从第一个参数开始代表窗口类名Chap1Exa1,窗口名为Chap1Exa1,重叠式窗口风格,左上角屏幕坐标,
宽度和高度,窗口无父窗口,窗口无主菜单,创建窗口的实例句柄,此窗口无创建参数****/
hwnd = CreateWindow(TEXT("FirstWinClass"), TEXT("FirstWinClass"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
HDC dc = GetDC(hwnd);
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nVersion = 1;
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_TYPE_RGBA;
pfd.iLayerType = PFD_MAIN_PLANE;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 24;
pfd.cStencilBits = 8;
int pixelFormatID = ChoosePixelFormat(dc, &pfd);
SetPixelFormat(dc, pixelFormatID, &pfd);
HGLRC rc = wglCreateContext(dc);
wglMakeCurrent(dc, rc);
glClearColor(41.0f / 255.0f, 71.0f / 255.0f, 121.0f / 255.0f, 1.0f);
glMatrixMode(GL_PROJECTION);//投影矩阵
glLoadIdentity();
gluPerspective(50.0f, 800.0f / 600.0f, 0.1f, 1000.0f);
glMatrixMode(GL_MODELVIEW);//模型视口矩阵
glLoadIdentity();
ShowWindow(hwnd, nCmdShow); //显示窗口
UpdateWindow(hwnd); //更新窗口的客户区
//以下消息循环
while (GetMessage(&msg, NULL, 0, 0)) //获取消息,遇WM_QUIT退出循环
{
TranslateMessage(&msg); //键盘消息转换
DispatchMessage(&msg); //派送消息给窗口函数
DrawSence();
SwapBuffers(dc);
}
return msg.wParam;
}
//窗口函数
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) //根据消息值转相应的消息处理
{
case WM_DESTROY: //撤消窗口消息
PostQuitMessage(0); //产生退出程序消息WM_QUIT
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);//其它转默认窗口函数
}
#include <gl/GL.h>
#include <gl/GLU.h>
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
void DrawSence()
{
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(10.0f);
glBegin(GL_POINTS);
glColor4ub(200, 0, 0, 255);
glVertex3f(0, 0, -100.0f);
glEnd();
}
//窗口函数声明
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//入口函数 WinMain()
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wndclass; //定义窗口类结构变量
HWND hwnd; //定义窗口句柄
MSG msg; //定义消息结构变量
/********定义窗口类各属性*******/
wndclass.style = CS_HREDRAW | CS_VREDRAW; //改变窗口大小则重画
wndclass.lpfnWndProc = WndProc; //窗口函数为 WndProc
wndclass.cbClsExtra = 0; //窗口类无扩展
wndclass.cbWndExtra = 0; //窗口实例无扩展
wndclass.hInstance = hInstance; //注册窗口类的实例句柄
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); //窗口用默认图标
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); //窗口用箭头光标
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); //背景为白色
wndclass.lpszMenuName = NULL; //窗口默认无菜单
wndclass.lpszClassName = TEXT("FirstWinClass"); //窗口类名为FirstWinClass
/**********************************/
if (!RegisterClass(&wndclass)) return FALSE; //注册窗口类,失败则返回
//创建窗口
/****从第一个参数开始代表窗口类名Chap1Exa1,窗口名为Chap1Exa1,重叠式窗口风格,左上角屏幕坐标,
宽度和高度,窗口无父窗口,窗口无主菜单,创建窗口的实例句柄,此窗口无创建参数****/
hwnd = CreateWindow(TEXT("FirstWinClass"), TEXT("FirstWinClass"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
HDC dc = GetDC(hwnd);
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nVersion = 1;
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_TYPE_RGBA;
pfd.iLayerType = PFD_MAIN_PLANE;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 24;
pfd.cStencilBits = 8;
int pixelFormatID = ChoosePixelFormat(dc, &pfd);
SetPixelFormat(dc, pixelFormatID, &pfd);
HGLRC rc = wglCreateContext(dc);
wglMakeCurrent(dc, rc);
glClearColor(41.0f / 255.0f, 71.0f / 255.0f, 121.0f / 255.0f, 1.0f);
glMatrixMode(GL_PROJECTION);//投影矩阵
glLoadIdentity();
gluPerspective(50.0f, 800.0f / 600.0f, 0.1f, 1000.0f);
glMatrixMode(GL_MODELVIEW);//模型视口矩阵
glLoadIdentity();
ShowWindow(hwnd, nCmdShow); //显示窗口
UpdateWindow(hwnd); //更新窗口的客户区
//以下消息循环
while (GetMessage(&msg, NULL, 0, 0)) //获取消息,遇WM_QUIT退出循环
{
TranslateMessage(&msg); //键盘消息转换
DispatchMessage(&msg); //派送消息给窗口函数
DrawSence();
SwapBuffers(dc);
}
return msg.wParam;
}
//窗口函数
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) //根据消息值转相应的消息处理
{
case WM_DESTROY: //撤消窗口消息
PostQuitMessage(0); //产生退出程序消息WM_QUIT
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);//其它转默认窗口函数
}