我最近对C ++和OpenGL编程感兴趣,我尝试了几种类型的代码,它们都运行得很顺利......然后我被要求测试这段代码,但由于某些原因我得到错误所有的时间......现在我迷失了我应该做的事情......
#define WIN32_LEAN_AND_MEAN //include only needed libraries
#include <windows.h> //include necessary windows definitions
#include <GL/glut.h> //include openGL functionality
#include "myMD2.h"
BOOL stillActive; //status checker
BOOL Keys[256]; //different keys that the user can click on
HDC global_Hdc; //Handle Device Context
int winWidth;
int winHeight;
myMD2 *myMD2;
LRESULT CALLBACK myWndProc(HWND hwnd, UINT uint, WPARAM wParam, LPARAM lParam);
void mySetPixel (HDC pixHDC);
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hThisTust, LPSTR lpArgs,int iCmd)
{
HWND myHwnd;
MSG myMsg;
WNDCLASSEX myWndClass;
static TCHAR myClass[] = TEXT("myclass");
myWndClass.cbClsExtra = 0;
myWndClass.cbSize = sizeof(WNDCLASSEX);
myWndClass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
myWndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
myWndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
myWndClass.hIconSm = NULL;
myWndClass.hInstance = hThisTust;
myWndClass.lpfnWndProc = myWndProc;
myWndClass.lpszClassName = myClass;
myWndClass.lpszMenuName = NULL;
myWndClass.style =
CS_HREDRAW | CS_VREDRAW;
if(!RegisterClassEx(&myWndClass)){
MessageBox(NULL, TEXT("cannot register class"), TEXT("Error"), MB_OK | MB_ICONERROR);
return(0);
}
myHwnd = CreateWindowEx(WS_EX_APPWINDOW, myClass, NULL, WS_POPUP,0,0,1024,768,NULL, NULL, hThisTust, NULL);
if(!myHwnd){
MessageBox(NULL, TEXT("cannot create window"), TEXT("Error"), MB_OK | MB_ICONERROR);
return(0);
}
ShowWindow(myHwnd, iCmd);
UpdateWindow(myHwnd);
stillActive = TRUE;
while(stillActive){ //Entering game loop
if(PeekMessage(&myMsg, NULL, 0,0, PM_REMOVE) == WM_QUIT)
stillActive = FALSE;
else{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0,0,1024,768);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,1024/768,1.0f,1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
myMD2 -> draw();
SwapBuffers(global_Hdc);
TranslateMessage(&myMsg);
DispatchMessage(&myMsg);
}
}
return myMsg.wParam;
}
LRESULT CALLBACK myWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
HDC myHdc;
HGLRC myHglrc; //Handle Graphics Library Resource Context
switch(msg){
case WM_CREATE:
myHdc = GetDC(hwnd);
global_Hdc = myHdc;
mySetPixel(myHdc);
myHglrc = wglCreateContext(myHdc);
wglMakeCurrent(myHdc, myHglrc);
myMD2 = new MYMD2();
myMD2->setup();
myMD2->angle += 180;
myMD2->obj3D.SetAnim(1);
return(0);
break;
case WM_KEYDOWN:
Keys[wParam] = TRUE;
if (Keys['Q']) //Keys[VK_ESCAPE]
stillActive = FALSE;
if (Keys[VK_SPACE]) //If the spacebar is pressed
myMD2->obj3D.SetAnim(6);
return(0);
break;
case WM_KEYUP:
if (Keys[VK_SPACE])
myMD2->obj3D.SetAnim(1);
Keys[wParam] = FALSE;
return(0);
break;
case WM_SIZE:
winWidth = LOWORD(lParam);
winHeight = HIWORD(lParam);
if (winHeight == 0)
winHeight = 1;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0,0,1024,768);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,1024/768,1.0f,1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
return(0);
break;
case WM_CLOSE:
if(myHdc){
ReleaseDC(hwnd, myHdc);
}
if(myHglrc){
wglMakeCurrent(NULL, NULL);
wglDeleteContext(myHglrc);
}
PostQuitMessage(0);
return(0);
break;
case WM_DESTROY:
if(myHdc){
ReleaseDC(hwnd, myHdc);
}
if(myHglrc){
wglMakeCurrent(NULL, NULL);
wglDeleteContext(myHglrc);
}
PostQuitMessage(0);
return(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
break;
}
}
void mySetPixel(HDC myPixHdc){
int mySelected;
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
};
mySelected = ChoosePixelFormat(myPixHdc, &pfd);
SetPixelFormat(myPixHdc, mySelected, &pfd);
}
myMD2.h
#ifndef MY_MD2_H
#define MY_MD2_H
typedef void* md2_t;
md2_t md2_open(const char *filename);
void md2_close(md2_t h);
void md2_desc(md2_t h);
void md2_frame_sample(md2_t _h);
void md2_draw(md2_t h);
#endif
答案 0 :(得分:0)
头文件myMD2.h
未定义名为myMD2
的类或结构。从其余的代码我猜你已经下载了错误的头文件。