PDA

View Full Version : OSX 1.7 does not draw anything



Crashdog
02-05-2012, 04:25 PM
Hello,
I've used opengl 1.2 for quite many years and want to expand to opengl 3.2+ now. I have a mini mac (osx 1.7.3 Nvidia GeForce 9400) and have looked into several webpages with OpenGL examples. So far I haven't gotten any one to work. The examples on opengl-tutorial.org don't compile - respectivly Link.
I have installed GLEW (1.7.0) and GLFW (2.7.2) manualy which compiled with no errors or warnings. Installed with sudo.
Now I have tried to put together a minimalistic programm (from the different example sources). This compiles and links but shows nothing but a black screen. If I set glClearColor it will clear the screen to the set color. But nothing is drawn. Here's the code:
// Include standard headers
#include <stdio.h>
#include <stdlib.h>

// Include GLEW
#include <GL/glew.h>

// Include GLFW
#include <GL/glfw.h>

// Include GLM
//#include <glm/glm.hpp>
//using namespace glm;

int main( void )
{
// Initialise GLFW
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
return -1;
}

glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

// Open a window and create its OpenGL context
if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW ) )
{
fprintf( stderr, "Failed to open GLFW window\n" );
glfwTerminate();
return -1;
}

// Initialize GLEW
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
return -1;
}

glfwSetWindowTitle( "Tutorial 01" );

// Ensure we can capture the escape key being pressed below
glfwEnable( GLFW_STICKY_KEYS );

// Dark blue background
glClearColor(0.0f, 0.0f, 0.3f, 0.0f);
// An array of 3 vectors which represents 3 vertices
static const GLfloat g_vertex_buffer_data[] = {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
};

// This will identify our vertex buffer
GLuint vertexbuffer;

// Generate 1 buffer, put the resulting identifier in vertexbuffer
glGenBuffers(1, &amp;vertexbuffer);

// The following commands will talk about our 'vertexbuffer' buffer
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);

// Give our vertices to OpenGL.
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);

do{
// Draw nothing, see you in tutorial 2 !

// 1rst attribute buffer : vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);

// Draw the triangle !
glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle

glDisableVertexAttribArray(0);
// Swap buffers
glfwSwapBuffers();

} // Check if the ESC key was pressed or the window was closed
while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &amp;&amp;
glfwGetWindowParam( GLFW_OPENED ) );

// Close OpenGL window and terminate GLFW
glfwTerminate();

return 0;
}

I also tried one with vertex and fragment shaders with the same result that nothing is drawn. Just a black screen.

Hope any one with more experiance on the subject can give me a hint what the cause of the problem might be.

Yours,
Crashdog

menzel
02-06-2012, 02:25 AM
Hi,


you will need to use a VertexArrayObject, per default VAO 0 is bound which will lead to an INVALID_OPERATION if you try to draw something.
A vertex and fragment shader is also mandatory.
Note that GLEW will throw an INVALID_ENUM as it tries to get the extension list with a deprecated call, you can ignore the error but you will have to live without any extensions (GLEW still does not play well with core).

Crashdog
02-08-2012, 11:14 AM
Hello,
@menzel, thanks for your input.

So far the only source of examples I could find that works are these https://github.com/beelsebob/Cocoa-GL-Tutorial. The link came from a thread in the opengl in the Macintosh section. All other examples using glew and glfw had different issues. Either not compilable or do not run as expected. I could compile the previously mentioned opengl-tutorial.org examples my making my own Makefile. But resulting in the same problem that nothing is drawn to the screen. As I'm still new to OGL 3.2+ I can't say what the cause is and it might just as well be my lack of knowledge.
However the examples from beelzebob are woking fine on osx 10.7.3 with nvidia 9400 chip using OGL 3.2 and glsl 150 core.

Just thought I mention that here in case some other OGL 3.2+ (OSX) newbie has similar issues and is looking for a starting point.

And just to mention it, I also tried compiling the glew / glfw examples on an Ubuntu 10.xx machine which has similar issues as the mac.

Crashdog