【发布时间】:2018-08-21 21:34:36
【问题描述】:
我的窗口上什么都没有显示,只有黑色纯色,构建继续进行,但没有其他任何事情发生..
我也在 Windows 上尝试了相同的代码,但仍然没有。
这是我的代码:
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#if defined(__APPLE__)
#include <GLUT/GLUT.h>
#include <OpenGL/gl3.h>
#include <OpenGL/glu.h>
#else
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
#include <windows.h>
#endif
#include <GL/glew.h> // must be downloaded
#include <GL/freeglut.h> // must be downloaded unless you have an Apple
#endif
using namespace std;
void changeViewPort(int w, int h)
{
glViewport(0, 0, w, h);
}
void render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex2f(0.5, 0.5);
glVertex2f(-0.5, -0.5);
glVertex2f(1.5, 1.5);
glEnd();
glutSwapBuffers();
}
int main(int argc, char* argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutCreateWindow("Hello, GL");
glutReshapeFunc(changeViewPort);
glutDisplayFunc(render);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0,400,0,500);
glutMainLoop();
return 0;
}
【问题讨论】:
标签: c++ xcode macos opengl glut