| Код | #include <windows.h> #pragma comment (lib,"glaux.lib") #include <GL/gl.h> #include <GL/glu.h>
#include <math.h>
LONG WINAPI WndProc(HWND, UINT, WPARAM,LPARAM);
HDC hDC; HGLRC hRC;
int SetPixelFormat(); void Display(void); void Resize(int weight,int height); //void Axis(void); void MyObj(void);
const double pi = 3.1415926535; //Костанта числа Пи
double _object[6][4] = { 0, 2, 4, 1, //Матрица объекта 0, 1, 6, 1, 0, 4, 9, 1, 0, 6, 6, 1, 0, 5, 4, 1, 0, 13,14,1};
double _default_object[6][4] = { 0, 2, 4, 1, //Матрица исходного объекта 0, 1, 6, 1, 0, 4, 9, 1, 0, 6, 6, 1, 0, 5, 4, 1, 0, 13,14,1};
void ChangeMatrix(double CurrMatrix[6][4]) { double temp[6][4] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0}; int i,j,k;
for(i=0; i<6; i++) //Перемножение матрицы объекта for(j=0; j<4; j++) for(k=0; k<4; k++) temp[i][j] += _object[i][k] * CurrMatrix[k][j];
for(i=0; i<6; i++) //Сохранение перемножения в матрицу объекта for(j=0; j<4; j++) _object[i][j] = temp[i][j]; }
int SetPixelFormat() { int m_GLPixelIndex; PIXELFORMATDESCRIPTOR pfd; pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 32; pfd.cRedBits = 8; pfd.cRedShift = 16; pfd.cGreenBits = 8; pfd.cGreenShift = 8; pfd.cBlueBits = 0; pfd.cBlueShift = 0; pfd.cAlphaBits = 0; pfd.cAlphaShift = 0; pfd.cAccumBits = 64; pfd.cAccumRedBits = 16; pfd.cAccumGreenBits = 16; pfd.cAccumBlueBits = 16; pfd.cAccumAlphaBits = 0; pfd.cDepthBits = 32; pfd.cStencilBits = 8; pfd.cAuxBuffers = 0; pfd.iLayerType = PFD_MAIN_PLANE; pfd.bReserved = 0; pfd.dwLayerMask = 0; pfd.dwVisibleMask = 0; pfd.dwDamageMask = 0; m_GLPixelIndex = ChoosePixelFormat(hDC,&pfd); if(m_GLPixelIndex==0) { m_GLPixelIndex = 1; if(DescribePixelFormat(hDC,m_GLPixelIndex,sizeof(PIXELFORMATDESCRIPTOR),&pfd)==0) return 0; }
if (SetPixelFormat( hDC, m_GLPixelIndex, &pfd)==FALSE) return 0; return 1; }
void MyObj(void) { int i; glLineWidth(2); glColor3d(255,0,0);
glBegin(GL_LINES); for(i=0; i<5; i++) { glVertex4d(_object[i][0], _object[i][1], _object[i][2], 1); glVertex4d(_object[i+1][0], _object[i+1][1], _object[i+1][2],1); }
for(i=0; i<5; i++) { glVertex4d(_object[i][0], _object[i][1], _object[i][2],1); glVertex4d(_object[5][0], _object[5][1], _object[5][2],1); } glEnd();
glColor3d(0,1,0); // Прорисовка начальной точки объекта glPointSize(5); glBegin(GL_POINTS); glVertex4d(_object[0][0],_object[0][1],_object[0][2],1); glEnd(); //glPointSize(1); }
void Display(void) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); MyObj(); glFinish(); SwapBuffers(wglGetCurrentDC()); }
void Resize(int width,int height) { glViewport(0,0,width,height); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho(-10,10, -10,10, -10,10); gluLookAt( 0,0,1, 0,0,0, 0,1,0 ); glMatrixMode( GL_MODELVIEW ); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
HWND hwnd; MSG msg; WNDCLASS WndClass; memset(&WndClass,0,sizeof(WNDCLASS)); WndClass.style = CS_HREDRAW | CS_VREDRAW; WndClass.lpfnWndProc = WndProc; WndClass.hInstance = hInstance; WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); WndClass.lpszClassName = L"Lab"; WndClass.hCursor = LoadCursor(NULL,IDC_HAND); RegisterClass(&WndClass); hwnd = CreateWindow(L"Lab",L"OpenGL", WS_OVERLAPPEDWINDOW, 100,100,500,500, NULL, NULL, hInstance, NULL); ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while(1) { while(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE)) if(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } else return 0; Display(); } }
LONG WINAPI WndProc(HWND hwnd, UINT Message, WPARAM wparam, LPARAM lparam) { PAINTSTRUCT PaintStruct; double scale = 1.05;
switch (Message){ case WM_SIZE: Resize( LOWORD(lparam), HIWORD(lparam) ); break;
case WM_CREATE: hDC = GetDC(hwnd); SetPixelFormat(); hRC = wglCreateContext(hDC); wglMakeCurrent(hDC,hRC); glEnable(GL_ALPHA_TEST); glEnable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); break;
case WM_DESTROY: if (hRC) { wglMakeCurrent(NULL,NULL); wglDeleteContext(hRC); } ReleaseDC(hwnd,hDC); PostQuitMessage(0); break;
case WM_PAINT: BeginPaint(hwnd,&PaintStruct); Display(); EndPaint(hwnd,&PaintStruct); break; case WM_KEYDOWN: switch(wparam) { case VK_LEFT:glTranslated(0.5,0,0);break; //сдвиг рисунка влево case VK_RIGHT:glTranslated(-0.5,0,0);break;//сдвиг рисунка вправо case VK_UP:glTranslated(0,-0.5,0);break;//сдвиг рисунка вверх case VK_DOWN:glTranslated(0,0.5,0);break;//сдвиг рисунка вниз } break; default: return DefWindowProc(hwnd, Message, wparam, lparam); } return 0; }
|
Выдаёт кучу ошибок: Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__glPointSize@4 referenced in function "void __cdecl MyObj(void)" (?MyObj@@YAXXZ) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function "void __cdecl MyObj(void)" (?MyObj@@YAXXZ) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__glVertex4d@32 referenced in function "void __cdecl MyObj(void)" (?MyObj@@YAXXZ) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function "void __cdecl MyObj(void)" (?MyObj@@YAXXZ) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__glColor3d@24 referenced in function "void __cdecl MyObj(void)" (?MyObj@@YAXXZ) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__glLineWidth@4 referenced in function "void __cdecl MyObj(void)" (?MyObj@@YAXXZ) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__wglGetCurrentDC@0 referenced in function "void __cdecl Display(void)" (?Display@@YAXXZ) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__glFinish@0 referenced in function "void __cdecl Display(void)" (?Display@@YAXXZ) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function "void __cdecl Display(void)" (?Display@@YAXXZ) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__gluLookAt@72 referenced in function "void __cdecl Resize(int,int)" (?Resize@@YAXHH@Z) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__glOrtho@48 referenced in function "void __cdecl Resize(int,int)" (?Resize@@YAXHH@Z) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__glLoadIdentity@0 referenced in function "void __cdecl Resize(int,int)" (?Resize@@YAXHH@Z) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__glMatrixMode@4 referenced in function "void __cdecl Resize(int,int)" (?Resize@@YAXHH@Z) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__glViewport@16 referenced in function "void __cdecl Resize(int,int)" (?Resize@@YAXHH@Z) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__glTranslated@24 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__wglDeleteContext@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__glEnable@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__wglMakeCurrent@8 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) Lab_KG2.obj : error LNK2019: unresolved external symbol __imp__wglCreateContext@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) C:\Documents and Settings\Hysteria\Мои документы\Visual Studio 2008\Projects\Lab_KG2\Debug\Lab_KG2.exe : fatal error LNK1120: 19 unresolved externals
Приложение Win32, пустое.
В чём ошибка? Заранее спасибо.
|