Results 1 to 3 of 3

Thread: OSX 1.7 does not draw anything

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2012
    Posts
    2

    OSX 1.7 does not draw anything

    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

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jan 2012
    Location
    Germany
    Posts
    325

    Re: OSX 1.7 does not draw anything

    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).

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2012
    Posts
    2

    Re: OSX 1.7 does not draw anything [solved]

    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

Similar Threads

  1. Rendering terrain - multiple draw calls or draw whole VBO?
    By rakketh in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 07-19-2013, 02:26 PM
  2. How do I draw separate triangles (not attached) in one draw call?
    By Spankenstein in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-04-2012, 05:48 AM
  3. Draw at 3D
    By GLman in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 06-05-2002, 05:25 AM
  4. How draw...
    By ByteZero in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-26-2001, 01:01 PM
  5. It just won't draw
    By imported_Robin in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-14-2000, 12:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean