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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
| #include <windows.h>
#include <Gl/gl.h>
#include <Gl/glu.h>
#include <Gl/glaux.h>
#pragma hdrstop
float angle=0.0f;
HDC g_HDC;
//---------------------------------------------------------------------------
#pragma argsused
//---------------------------------------------------------------------------
void SetupPixelFormat(HDC hDC)
{
int npixelformat;
static PIXELFORMATDESCRIPTOR pfd={
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0,0,0,0,0,0,
0,
0,
0,
0,0,0,0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0};
npixelformat=ChoosePixelFormat(hDC,&pfd);
SetPixelFormat(hDC,npixelformat,&pfd);
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
static HGLRC hRC;
static HDC hDC;
char string[]="bonjour";
int width,height;
switch(message)
{
case WM_CREATE:
hDC =GetDC(hwnd);
g_HDC=hDC;
SetupPixelFormat(hDC);
hRC=wglCreateContext(hDC);
wglMakeCurrent(hDC,hRC);
return 0;
break;
case WM_CLOSE:
wglMakeCurrent(hDC,NULL);
wglDeleteContext(hRC);
PostQuitMessage(0);
return 0;
break;
case WM_SIZE:
height=HIWORD(lParam);
width=LOWORD(lParam);
if (height==0)
{
height=1;
}
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
return 0;
break;
default: break;
}
return (DefWindowProc(hwnd,message,wParam,lParam));
}
int WINAPI WinMain (HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,
int nShowCmd)
{
WNDCLASSEX windowClass;
HWND hwnd;
MSG msg;
bool done;
windowClass.cbSize=sizeof(WNDCLASSEX);
windowClass.style=CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc=WndProc;
windowClass.cbClsExtra=0;
windowClass.cbWndExtra=0;
windowClass.hInstance=hInstance;
windowClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
windowClass.hCursor=LoadCursor(NULL,IDC_ARROW);
windowClass.hbrBackground=NULL;
windowClass.lpszMenuName=NULL;
windowClass.lpszClassName="Maclass";
windowClass.hIconSm=LoadIcon(NULL,IDI_WINLOGO);
if (!RegisterClassEx(&windowClass))
return 0;
hwnd =CreateWindowEx(NULL,
"maclass",
"opengl apllication",
WS_OVERLAPPEDWINDOW | WS_VISIBLE |
WS_SYSMENU | WS_CLIPCHILDREN |
WS_CLIPSIBLINGS,
100,100,
400,400,
NULL,
NULL,
hInstance,
NULL);
if (!hwnd)
return 0;
ShowWindow(hwnd,SW_SHOW);
UpdateWindow(hwnd);
done=false;
while (!done)
{
PeekMessage(&msg,hwnd,NULL,NULL,PM_REMOVE);
if (msg.message==WM_QUIT)
{
done=true;
}
else
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
angle=angle+0.1f;
if (angle >=360.0f)
angle = 0.0f;
glTranslatef(0.0f,0.0f,-5.0f);
glRotatef(angle,0.0f,0.0f,1.0f);
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_TRIANGLES);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(1.0f,0.0f,0.0f);
glVertex3f(1.0f,1.0f,0.0f);
glEnd();
SwapBuffers(g_HDC);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
} |
Partager