我花了几个小时测试和试验不同的解决方案,但最终奏效的是:
/* Maximize window using Windows API after glutCreateWindow() has been called */
HWND win_handle = FindWindow(0, L"Stackoverflow");
if (!win_handle)
{
printf("!!! Failed FindWindow\n");
return -1;
}
SetWindowLong(win_handle, GWL_STYLE, (GetWindowLong(win_handle, GWL_STYLE) | WS_MAXIMIZE));
ShowWindowAsync(win_handle, SW_SHOWMAXIMIZED);
/* Activate GLUT main loop */
glutMainLoop();
这很简单,我只是想同情你只能glutMainLoop()
在最后打电话。
现在,既然您正在寻找一个跨平台的解决方案,我必须说这种方法是一个糟糕的主意。让我分享一些其他的方法:
这是一个最小、完整且可验证的示例的源代码(适用于 Windows):
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <GL/glut.h>
int WIDTH = 480;
int HEIGHT = 480;
void initializeGL()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLfloat aspect = (GLfloat) WIDTH / HEIGHT;
gluPerspective(45, aspect, 1.0f, 500.0f);
glViewport(0, 0, WIDTH, HEIGHT);
glMatrixMode(GL_MODELVIEW);
glShadeModel( GL_SMOOTH );
glClearDepth( 1.0f );
glEnable( GL_DEPTH_TEST );
glDepthFunc( GL_LEQUAL );
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
glClearColor(0.0, 0.0, 0.0, 1.0);
}
void displayGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-3.0f);
glBegin(GL_TRIANGLES);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
glutSwapBuffers();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("Stackoverflow");
glutDisplayFunc(displayGL);
initializeGL();
/* Maximize window using Windows API */
HWND win_handle = FindWindow(0, L"Stackoverflow");
if (!win_handle)
{
printf("!!! Failed FindWindow\n");
return -1;
}
SetWindowLong(win_handle, GWL_STYLE, (GetWindowLong(win_handle, GWL_STYLE) | WS_MAXIMIZE));
ShowWindowAsync(win_handle, SW_SHOWMAXIMIZED);
/* Activate GLUT main loop */
glutMainLoop();
return 0;
}