s3lph
s3lph

Reputation: 4655

OpenGL not drawing triangles

I'm using this tutorial to learn some OpenGL.

But the code doesn't work - no triangle is shown. However, the point at (0|0|0) in the previous tutorial page was drawn.

Here's my code:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include "vector3f.hpp"

GLuint VBO;

static void RenderSceneCB()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glDrawArrays(GL_TRIANGLES, 0, 3);
    glDisableVertexAttribArray(0);
    glutSwapBuffers();
}

static void InitializeGlutCallbacks()
{
    glutDisplayFunc(RenderSceneCB);
}

static void CreateVertexBuffer()
{
    Vector3f Vertices[3];
    Vertices[0] = Vector3f(-.5f, -.5f, .0f);
    Vertices[1] = Vector3f(.5f, -.5f, .0f);
    Vertices[2] = Vector3f(.0f, .5f, .0f);

    glGenBuffers(1, &VBO);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
}

int main(int argc, char* argv[]) {
    short w = 640, h = 480;
    short sw, sh;
    setenv("DISPLAY", ":0.0", 0);
    glutInit(&argc, argv);
    sw = glutGet(GLUT_SCREEN_WIDTH);
    sh = glutGet(GLUT_SCREEN_HEIGHT);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowSize(w, h);
    glutInitWindowPosition((short)(sw-w)/2, (short)(sh-h)/2);
    glutCreateWindow("Tutorial 03");
    InitializeGlutCallbacks();

    GLenum res = glewInit();
    if (res != GLEW_OK) {
        fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
        return 1;
    }

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    CreateVertexBuffer();

    glutMainLoop();

    return 0;
}

Why isn't it working? I've linked all libraries (libGL.so, libglut.so, libGLEW.so)

I'm using Ubuntu Raring x64

Upvotes: 0

Views: 1225

Answers (1)

Anton D
Anton D

Reputation: 1366

The answer is explained in the faq: http://ogldev.atspace.co.uk/faq.html. Rendering without shaders works only on some computers.

Upvotes: 4

Related Questions