Reputation: 401
I'm doing a bit of OpenGL/C work for University (I've experience in WebGL). The code below is is mostly based on the gltut tutorials (which won't run on OSX - need OGL 3.3) and NeHe ones too. My problem is, no matter what, the only thing drawn is the initial window filled with any one color (changing the color in the while loop works, so the loop is running correctly). The triangle and quad, however, do not appear at all. I've been troubleshooting it for the last 5 hours and I'm no further than when I started. Any help would be greatly appreciated!
Using: OpenGL3.2, latest GLFW (2.7.7)
Compiling using: gcc main.c -I/usr/local/include -I/opt/X11/include -L/usr/local/lib -I/opt/X11/lib -w -framework OpenGL -framework Cocoa -framework IOKit -lglfw -o test
Code in my comment below works.
Upvotes: 1
Views: 1303
Reputation: 76842
I ran into the same issue. I had to create a VAO before my VBO's and now it works on OS X.
GLuint vertex_array;
glGenVertexArrays(1, &vertex_array);
glBindVertexArray(vertex_array);
Upvotes: 1
Reputation: 401
Fixed code below (3.2 OGL context bits are commented because they do not work - blank screen as described above):
//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;
}
Upvotes: 0
Reputation: 16612
You do not appear to be initialising your matrices - neither the projection, nor the modelview.
And even if the default matrices were, by chance, reasonable for your purposes, you then continually apply translations, which will very quickly result in things being off-screen anyway.
Upvotes: 2