固定碼(3.2 OGL背景下位評論,因爲他們沒有工作 - 黑屏如上所述):
//c-libs
#include <stdlib.h>
//opengl
#include <OpenGL/gl3.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
//glfw
#define GLFW_INCLUDE_GL3 /* don't drag in legacy GL headers. */
#define GLFW_NO_GLU /* don't drag in the old GLU lib - unless you must. */
#include <GL/glfw.h>
int init() {
//init glfw
if(!glfwInit())
return -1;
//DOES NOT WORK
//set to version 3.2 & use core profile
//glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
//glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
//glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
//glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
/* Create a windowed mode window and its OpenGL context */
if (!glfwOpenWindow(1000, 500, 5, 6, 5, 0, 0, 0, GLFW_WINDOW))
return -1;
glfwSetWindowTitle("My Amazing Super Fantastic Window");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float aspect_ratio = ((float)1000)/500;
glFrustum(.5, -.5, -.5 * aspect_ratio, .5 * aspect_ratio, 1, 50);
glMatrixMode(GL_MODELVIEW);
return 1;
}
int main(int argc, char *argv[])
{
if(!init())
return -1;
/* Loop until the user closes the window */
int running = GL_TRUE;
while (1)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// reset view matrix
glLoadIdentity();
// move view back a bit
glTranslatef(0, 0, -30);
// by repeatedly rotating the view matrix during drawing, the
// squares end up in a circle
int i = 0, squares = 15;
float red = 1, blue = 1, green = 1;
for (; i < squares; ++i){
glRotatef(360.0/squares, 0, 0, 1);
glBegin(GL_QUADS); {
glColor3f(red, green, blue);
glVertex2i(1, 11);
glColor3f(red * .8, green * .8, blue * .8);
glVertex2i(-1, 11);
glColor3f(red * .5, green * .5, blue * .5);
glVertex2i(-1, 9);
glColor3f(red * .8, green * .8, blue * .8);
glVertex2i(1, 9);
} glEnd();
}
/* Swap front and back buffers and process events */
glfwSwapBuffers();
}
return 0;
}
你可以嘗試一次拉它,然後做',而(1);'這可能只是不斷地重繪不給它一個在屏幕上顯示的機會。 (你可能想要使用FreeGLUT或其他東西,而不是這樣做)。 – 2013-03-11 21:22:00
OS X上的核心配置文件不支持即時模式/固定管道命令。 – 2013-03-12 00:24:47
如果您遇到更多問題或需要參考,我正在將NeHe的教程移植到glfw,您可以在我的[網站]上找到詳細信息(http://www.pjreddie.com/projects/nehe-tutorials - 使用 - GLFW /)。 – pjreddie 2013-03-12 20:56:52