This is my script
i have no idea to solve this error
Please help me
Thank you so much
这是我的脚本,我不知道如何解决这个错误,请帮帮我谢谢
float angle = 15;
float x, y, z; // for polygon rotate
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // clear screen and depth buffer
glLoadIdentity();
glPushMatrix();
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_POLYGON);
glVertex2f(160.0, 360.0);
glVertex2f(300.0, 360.0);
glVertex2f(160.0, 480.0);
glVertex2f(300.0, 480.0);
glPushMatrix();
glColor3f(0.0, 0.0, 0.0);
glVertex2f(580.0, 200.0);
glVertex2f(640.0, 200.0);
glVertex2f(580.0, 480.0);
glVertex2f(640.0, 480.0);
glRotatef(angle, -1.0f, 0.0, 0.0);
angle += 15.0f;
glEnd();
glutSwapBuffers(); // dounle buffering
}
LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_LBUTTONDOWN:
{
}break;
case WM_DESTROY: {
PostQuitMessage(0);
}break;
default:break;
}
return 0;
}
int main(int argc, char** argv)
{
glutInit(&argc, argv); // Initialize GLUT
glutInitDisplayMode(GLUT_DOUBLE);// Set up some memory buffers for our display
glutInitWindowSize(640, 400);
glutInitWindowPosition(100, 20);
glutCreateWindow("My GLUT GAME");
glutDisplayFunc(display);
//glutKeyboardFunc();
glutMainLoop();
return 0;
}
更多回答
A linker error will be coming from you you build (and link) your code. Are you using Visual Studio? What kind of project have you built?
链接器错误将来自您构建(和链接)您的代码。您使用的是Visual Studio吗?你们建了什么样的项目?
A Windows project requires WinMain
instead of main
.
Windows项目需要WinMain而不是Main。
Please do consider accepting an answer, if it solves the problem. If not, please comment underneath each answer stating why they do not work.
如果答案能解决问题,请考虑接受。如果没有,请在每个答案下面注明它们不起作用的原因。
优秀答案推荐
I had to make the application as executable project with output type .exe
Key change was changing Linker -> System -> Sub-system to Console
我不得不将应用程序作为输出类型为.exe的可执行项目,关键更改是将Linker->System->Subsystem更改为Console
You've set the project to build as a Windows application, not a command line application. Change int main()
to:
您已将项目设置为构建为Windows应用程序,而不是命令行应用程序。将int main()更改为:
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow)
Int回调WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR pCmdLine,int nCmdShow)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633559%28v=vs.85%29.aspx
Https://msdn.microsoft.com/en-us/library/windows/desktop/ms633559%28v=vs.85%29.aspx
Or, change your project properties to be a command line application.
或者,将项目属性更改为命令行应用程序。
As workaround you can add WinMain
function from which call main
:
作为解决办法,您可以添加WinMain函数,从中调用Main:
#ifdef _WIN32
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
return main(__argc, __argv);
}
#endif
For me following this helped.
对我来说,遵循这一点很有帮助。
Go to properties->Linker -> System -> Sub-system
and choose "not set" or "Windows"
进入属性->链接器->系统->子系统,选择“未设置”或“窗口”
更多回答
Thanks a lot, this fixed the issue for me!
非常感谢,这为我解决了这个问题!
Wow your suggestion totally worked. Thanks for the idea!
哇,你的建议完全奏效了。谢谢你的主意!
It worked for me, but I would like to understand why?
这对我很管用,但我想知道为什么?
我是一名优秀的程序员,十分优秀!