我尝试设置一个简单的VisualStudio2010 OpenGL项目
我从一个新的Win32项目开始,用以下代码替换_tWinMain:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: Place code here.
//MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_GLPREDICTOR, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
HDC hdc = GetDC(hWnd);
if (hdc == NULL)
return FALSE;
if(!SetPF(hdc))
return FALSE;
mainApp = new GLPredictor(hdc);
HGLRC tmpContext = wglCreateContext (hdc);
wglMakeCurrent(hdc, tmpContext);
//create opengl 4.2 context
/*GLenum error = glewInit();
if(error != GLEW_OK)
return false;
int attributes[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
WGL_CONTEXT_MINOR_VERSION_ARB, 2,
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
0
};
if(wglewIsSupported("WGL_ARB_create_context")==1){
HGLRC context = wglCreateContextAttribsARB(hdc, NULL,attributes);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(tmpContext);
wglMakeCurrent(hdc,context);
}
else{
return FALSE;
}
int glVersion[2] = {-1,-1};
glGetIntegerv(GL_MAJOR_VERSION, &glVersion[0]);
glGetIntegerv(GL_MINOR_VERSION, &glVersion[1]);
std::cout<<"Using OpenGL: "<<glVersion[0]<<"."<<glVersion[1]<<std::endl;
*/
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_GLPREDICTOR));
MSG msg = {0};
while(TRUE)
{
// Check to see if any messages are waiting in the queue
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if(msg.message == WM_QUIT)
break;
}
else
{
mainApp->render();
}
}
return (int) msg.wParam;
}
此操作。
但是只要我取消注释注释区域(//创建opengl 4.2上下文)并尝试运行应用程序,我就会立即收到一条错误消息:
The application was unable to start correctly (0x000007b). Click OK to close the application.
但是甚至没有达到未注释的代码。我甚至可以在_tWinMain的第一行设置一个断点,它不会被触发。
我已经尝试创建一个新项目并将代码复制过来,结果相同。
任何人都知道为什么这个区域导致项目崩溃,即使它包含的代码已经执行了?
//编辑:违规行似乎是
GLenum error = glewInit();
一旦它出现在代码中,就会使应用程序崩溃(尽管代码执行永远不会到达它)。这行是否会导致编译器添加一些可能导致问题的内容?
答案 0 :(得分:-1)
好的 - 我明白了。我不得不将“glew32.dll”复制到我的SysWOW64目录