aux程序

#include <windows.h> // Standard Window header required for all programs
#include <stdio.h>
#include <GL\gl.h> // OpenGL functions
#include <GL\glaux.h> // AUX Library functions
#include <iostream>

// Initial square position and size
GLfloat x = 100.0f;
GLfloat y = 150.0f;
GLsizei rsize = 50;

// Step size in x and y directions
// (number of pixels to move each time)
GLfloat xstep = 1.0f;
GLfloat ystep = 1.0f;

// Keep track of window’s changing width and height
GLfloat windowWidth;
GLfloat windowHeight;

// Called by AUX library when the window has changed size
void CALLBACK ChangeSize(GLsizei w, GLsizei h)
{
// Prevent a divide by zero, when window is too short
// (you can’t make a window of zero width)
if (h == 0)
h = 1;

// Set the viewport to be the entire window
glViewport(0, 0, w, h);

// Reset the coordinate system before modifying
glLoadIdentity();

// Keep the square square, this time, save calculated
// width and height for later use
if (w <= h)
{
windowHeight = 250.0f*h / w;
windowWidth = 250.0f;
}
else
{
windowWidth = 250.0f*w / h;
windowHeight = 250.0f;
}

// Set the clipping volume
glOrtho(-windowWidth/2, windowWidth/2, -windowHeight/2, windowHeight/2, 1.0f, -1.0f);
}

// Called by AUX library to draw scene
void CALLBACK RenderScene(void)
{
// Set background clearing color to blue
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);

// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);

// Set drawing color to red, and draw rectangle at
// current position.
glColor3f(1.0f, 0.0f, 0.0f);
//glRectf(x, y, x + rsize, y - rsize);
auxWireTeapot(50.0f);

glFlush();

auxSwapBuffers();
}
// Called by AUX library when idle (window not being
// resized or moved)
void CALLBACK IdleFunction(void)
{
// Reverse direction when you reach left or right edge
if (x > windowWidth - rsize || x < 0)
xstep = -xstep;

// Reverse direction when you reach top or bottom edge
if (y > windowHeight || y < rsize)
ystep = -ystep;

// Check bounds. This is in case the window is made
// smaller and the rectangle is outside the new
// clipping volume
if (x > windowWidth - rsize)
x = windowWidth - rsize - 1;

if (y > windowHeight)
y = windowHeight- 1;

// Actually move the square
x = x + xstep;
y = y + ystep;

// Redraw the scene with new coordinates
RenderScene();
}
void main(void)
{
// AUX window setup and initialization
auxInitDisplayMode(AUX_DOUBLE | AUX_RGBA);
auxInitPosition(100, 100, 250, 250);
auxInitWindow("Simple 2D Animation");

// Set function to call when window is resized
auxReshapeFunc(ChangeSize);

// Set function to call when program is idle
//auxIdleFunc(IdleFunction);

// Start main loop
auxMainLoop(RenderScene);

// Stop and wait for a keypress
//printf("Press any key to close the Window\n");
//getchar();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
gdi程序
#include <windows.h>

// 用于注册的窗口类名
const char g_szClassName[] = "myWindowClass";
// Handles to GDI brushes we will use for drawing
HBRUSH hBlueBrush, hRedBrush;
/*
* 第四步,窗口过程
*/
LRESULT CALLBACK MyWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
// Create a blue and red brush for drawing and filling
// operations. // Red, green, blue
break;
// 窗口绘制消息
case WM_PAINT:
/*
* 我们只需要在这里调用我们的 GDI 绘制函数就可以,其他地方可以先无视
*/
PAINTSTRUCT ps;
HBRUSH hOldBrush;

// Start painting
BeginPaint(hwnd, &ps);

// Select and use the red brush
hOldBrush = (HBRUSH)SelectObject(ps.hdc, hRedBrush);

// Draw a rectangle filled with the currently
// selected brush
Rectangle(ps.hdc, 100, 100, 150, 150);

// Deselect the brush
SelectObject(ps.hdc, hOldBrush);

// End painting
EndPaint(hwnd, &ps);
break;
// 窗口关闭消息
case WM_CLOSE:
DestroyWindow(hwnd);
break;
// 窗口销毁消息
case WM_DESTROY:
PostQuitMessage(0); // 发送离开消息给系统
break;
// 其他消息
default:
// pass 给系统,咱不管
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
/*
* 第一步,注册窗口类
*/
void RegisterMyWindow(HINSTANCE hInstance)
{
WNDCLASSEX wc;
hBlueBrush = CreateSolidBrush(RGB(0, 0, 255));
hRedBrush = CreateSolidBrush(RGB(255, 0, 0));
// 1)配置窗口属性
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = MyWindowProc; // 设置第四步的窗口过程回调函数
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
//wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hbrBackground = hBlueBrush; // Use blue brush for background

// 2)注册
if (!RegisterClassEx(&wc))
{
MessageBox(NULL, TEXT("窗口注册失败!"), TEXT("错误"), MB_ICONEXCLAMATION | MB_OK);
exit(0); // 进程退出
}
}
/*
* 第二步,创建窗口
*/
HWND CreateMyWindow(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
// Create the main application window
hWnd = CreateWindow(
g_szClassName,
g_szClassName,
WS_OVERLAPPEDWINDOW,
100, 100,250, 250, // Size and dimensions of window
NULL,NULL,hInstance,NULL);

if (hWnd == NULL)
{
MessageBox(NULL, TEXT("窗口创建失败!"), TEXT("错误"), MB_ICONEXCLAMATION | MB_OK);
exit(0); // 进程退出
}

// 显示窗口
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return hWnd;
}
/*
* 主函数
*/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
HWND hwnd;
MSG Msg;

// 第一步,注册窗口类
RegisterMyWindow(hInstance);
// 第二步:创建窗口
hwnd = CreateMyWindow(hInstance, nCmdShow);

// 第三步:消息循环
while (GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
gdi中使用opengl
#include <windows.h>

// 用于注册的窗口类名
const char g_szClassName[] = "myWindowClass";
// Handles to GDI brushes we will use for drawing
HBRUSH hBlueBrush, hRedBrush;
/*
* 第四步,窗口过程
*/
LRESULT CALLBACK MyWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
// Create a blue and red brush for drawing and filling
// operations. // Red, green, blue
break;
// 窗口绘制消息
case WM_PAINT:
/*
* 我们只需要在这里调用我们的 GDI 绘制函数就可以,其他地方可以先无视
*/
PAINTSTRUCT ps;
HBRUSH hOldBrush;

// Start painting
BeginPaint(hwnd, &ps);

// Select and use the red brush
hOldBrush = (HBRUSH)SelectObject(ps.hdc, hRedBrush);

// Draw a rectangle filled with the currently
// selected brush
Rectangle(ps.hdc, 100, 100, 150, 150);

// Deselect the brush
SelectObject(ps.hdc, hOldBrush);

// End painting
EndPaint(hwnd, &ps);
break;
// 窗口关闭消息
case WM_CLOSE:
DestroyWindow(hwnd);
break;
// 窗口销毁消息
case WM_DESTROY:
PostQuitMessage(0); // 发送离开消息给系统
break;
// 其他消息
default:
// pass 给系统,咱不管
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
/*
* 第一步,注册窗口类
*/
void RegisterMyWindow(HINSTANCE hInstance)
{
WNDCLASSEX wc;
hBlueBrush = CreateSolidBrush(RGB(0, 0, 255));
hRedBrush = CreateSolidBrush(RGB(255, 0, 0));
// 1)配置窗口属性
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = MyWindowProc; // 设置第四步的窗口过程回调函数
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
//wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hbrBackground = hBlueBrush; // Use blue brush for background

// 2)注册
if (!RegisterClassEx(&wc))
{
MessageBox(NULL, TEXT("窗口注册失败!"), TEXT("错误"), MB_ICONEXCLAMATION | MB_OK);
exit(0); // 进程退出
}
}
/*
* 第二步,创建窗口
*/
HWND CreateMyWindow(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
// Create the main application window
hWnd = CreateWindow(http://www.amjmh.com/v/BIBRGZ_558768/)
g_szClassName,
g_szClassName,
WS_OVERLAPPEDWINDOW,
100, 100,250, 250, // Size and dimensions of window
NULL,NULL,hInstance,NULL);

if (hWnd == NULL)
{
MessageBox(NULL, TEXT("窗口创建失败!"), TEXT("错误"), MB_ICONEXCLAMATION | MB_OK);
exit(0); // 进程退出
}

// 显示窗口
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return hWnd;
}
/*
* 主函数
*/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
HWND hwnd;
MSG Msg;

// 第一步,注册窗口类
RegisterMyWindow(hInstance);
// 第二步:创建窗口
hwnd = CreateMyWindow(hInstance, nCmdShow);

// 第三步:消息循环
while (GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

 

posted @ 2019-09-08 21:14  李艳艳665  阅读(273)  评论(0)    收藏  举报