简体   繁体   English

Mac OS X拒绝创建我的OpenGL窗口

[英]Mac OS X refuses to create my OpenGL Window

#include <iostream>
#include <GLUT/GLUT.h>
#include <OpenGL/OpenGL.h>

void GraphiqueAffichage() {
    glClearColor(1.0, 1.0, 0.5, 0.5);
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glFlush();
}

int main(int argc, const char * argv[]) {
    // insert code here...
    glutInitWindowPosition(10, 10);
    glutInitWindowSize(480, 272);
    glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
    glutCreateWindow("Bonjour");
    glutDisplayFunc(GraphiqueAffichage);
    glutMainLoop();
    return 0;
}

Hello I am on a Mac using OS X 10.12, ans with this code, no window is displayed, is it normal ? 您好,我在使用OS X 10.12的Mac上,使用此代码回答,没有窗口显示,这正常吗? Why ? 为什么呢 Please help me. 请帮我。 The compilation is correct, no error, build successful, but no window is created ! 编译正确,没有错误,编译成功,但是没有创建窗口! I tried this code that works with windows but I have a Mac and it does not work, how to make it working ? 我尝试了此代码,该代码可在Windows上使用,但我有Mac,但它不起作用,如何使其起作用?

The compilation is correct, no error, build successful ... 编译正确,没有错误,构建成功...

but you get a list of errors when you run the program, right? 但是在运行程序时会得到一个错误列表,对吗? "Successfully compiling" does not (alas) mean your code is correct. “成功编译”并不(alas)表示您的代码正确。

Looking up the very first error message, it seems you forgot to call glutInit first: 查找第一个错误消息,似乎您忘记了先调用glutInit

int main(int argc, char * argv[]) {
    glutInit(&argc, argv);
    glutInitWindowPosition(10, 10);
    ...

(right where your code says, "insert code here"...) (在您的代码显示为“在此处插入代码”的位置...)

man glutInit tells you why it failed as well: man glutInit告诉您为什么也失败:

glutInit will initialize the GLUT library and negotiate a session with the window system. glutInit将初始化GLUT库并与窗口系统协商会话。

where "the window system" is Mac OS X. 其中“窗口系统”是Mac OSX。

In addition, your main is wrong. 另外,您的main是错误的。 argv is not a const char * – with that const specifier, your compiler will yell at you. argv不是const char * –使用该const说明符,编译器会对您大喊大叫。

With these changes, I get a nice yellow window – your glClearColor – and with the custom title "Bonjour". 进行了这些更改后,我得到一个漂亮的黄色窗口-您的glClearColor并带有自定义标题“ Bonjour”。

You need initializer glut 您需要初始化器过剩

glutInit(&argc, argv); glutInit(&argc,argv);

in your main. 在你的主要。

//#include <iostream>
#include <GLUT/GLUT.h>
#include <OpenGL/OpenGL.h>

void GraphiqueAffichage() {
    glClearColor(1.0, 1.0, 0.5, 0.5);
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glFlush();
}

int main(int argc, const char * argv[]) {
    // insert code here...
    glutInit(&argc, argv);
    glutInitWindowPosition(10, 10);
    glutInitWindowSize(480, 272);
    glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
    glutCreateWindow("Bonjour");
    glutDisplayFunc(GraphiqueAffichage);
    glutMainLoop();
    return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM