Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8841983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:51:10+00:00 2026-06-14T10:51:10+00:00

I’m just trying to draw a bunch of lines that make up a cube.

  • 0

I’m just trying to draw a bunch of lines that make up a “cube”. I can’t for the life of me figure out why this is producing a black screen. The debugger does not break at any point.

I’m sure it’s a problem with my pointers, as I’m only decent at them in regular c++ and in OpenGL it gets even worse.

const char* vertexSource = 
    "#version 150\n"
    "in vec3 position;"
    "void main() {"
    "   gl_Position = vec4(position, 1.0);"
    "}";

const char* fragmentSource = 
    "#version 150\n"
    "out vec4 outColor;"
    "void main() {"
    "   outColor = vec4(1.0, 1.0, 1.0, 1.0);"
    "}";

int main() {

    initializeGLFW();

    // Initialize GLEW
    glewExperimental = GL_TRUE;
    glewInit();

    // Create Vertex Array Object
    GLuint vao;
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);

    // Create a Vertex Buffer Object and copy the vertex data to it
    GLuint vbo;
    glGenBuffers( 1, &vbo );

    float vertices[] = {
         1.0f,  1.0f,  1.0f, // Vertex 0 (X, Y, Z)
        -1.0f,  1.0f,  1.0f, // Vertex 1 (X, Y, Z)
        -1.0f, -1.0f,  1.0f, // Vertex 2 (X, Y, Z)
         1.0f, -1.0f,  1.0f, // Vertex 3 (X, Y, Z)
         1.0f,  1.0f, -1.0f, // Vertex 4 (X, Y, Z)
        -1.0f,  1.0f, -1.0f, // Vertex 5 (X, Y, Z)
        -1.0f, -1.0f, -1.0f, // Vertex 6 (X, Y, Z)
         1.0f, -1.0f, -1.0f  // Vertex 7 (X, Y, Z)
    };

    GLuint indices[] = {
        0, 1,
        1, 2,
        2, 3,
        3, 0,
        4, 5,
        5, 6,
        6, 7,
        7, 4,
        0, 4,
        1, 5,
        2, 6,
        3, 7
    };

    glBindBuffer( GL_ARRAY_BUFFER, vbo );
    glBufferData( GL_ARRAY_BUFFER, sizeof( vertices ), vertices, GL_STATIC_DRAW );
    //glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, vbo);
    //glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof( indices ), indices, GL_STATIC_DRAW );

    // Create and compile the vertex shader
    GLuint vertexShader = glCreateShader( GL_VERTEX_SHADER );
    glShaderSource( vertexShader, 1, &vertexSource, NULL );
    glCompileShader( vertexShader );

    // Create and compile the fragment shader
    GLuint fragmentShader = glCreateShader( GL_FRAGMENT_SHADER );
    glShaderSource( fragmentShader, 1, &fragmentSource, NULL );
    glCompileShader( fragmentShader );

    // Link the vertex and fragment shader into a shader program
    GLuint shaderProgram = glCreateProgram();
    glAttachShader( shaderProgram, vertexShader );
    glAttachShader( shaderProgram, fragmentShader );
    glBindFragDataLocation( shaderProgram, 0, "outColor" );
    glLinkProgram (shaderProgram);
    glUseProgram( shaderProgram);

    // Specify the layout of the vertex data
    GLint posAttrib = glGetAttribLocation( shaderProgram, "position" );
    glEnableVertexAttribArray( posAttrib );
    glVertexAttribPointer( posAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0 );

    // Main loop
    while(glfwGetWindowParam(GLFW_OPENED)) {

        // Clear the screen to black
        glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
        glClear( GL_COLOR_BUFFER_BIT );

        // Draw lines from 2 vertices
        glDrawElements(GL_LINES, sizeof(indices), GL_UNSIGNED_INT, indices );

        // Swap buffers
        glfwSwapBuffers();
    }

    // Clean up
    glDeleteProgram( shaderProgram );
    glDeleteShader( fragmentShader );
    glDeleteShader( vertexShader );

    //glDeleteBuffers( 1, &ebo );
    glDeleteBuffers( 1, &vbo );

    glDeleteVertexArrays( 1, &vao );

    glfwTerminate();
    exit( EXIT_SUCCESS );
}

EDIT: Full code trying the first answer’s recommendation. Still blank.

#define GLEW_STATIC

#include <GL/glew.h>
#include <GL/glfw.h>
#include <iostream>

#pragma comment( lib, "glfw.lib")
#pragma comment( lib, "opengl32.lib")
#pragma comment( lib, "glew32s.lib")

const char* vertexSource = 
    "#version 150\n"
    "in vec3 position;"
    "void main() {"
    "   gl_Position = vec4(position.x, position.y, position.z - 0.9, 1.0);"
    "}";

const char* fragmentSource = 
    "#version 150\n"
    "out vec4 outColor;"
    "void main() {"
    "   outColor = vec4(1.0, 1.0, 1.0, 1.0);"
    "}";

void initializeGLFW();

int main() {

    initializeGLFW();

    // Initialize GLEW
    glewExperimental = GL_TRUE;
    glewInit();

    // Create Vertex Array Object
    GLuint vao;
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);

    // Create a Vertex Buffer Object and copy the vertex data to it
    GLuint vbo;
    glGenBuffers( 1, &vbo );

    float vertices[] = {
         1.0f,  1.0f,  1.0f, // Vertex 0 (X, Y, Z)
        -1.0f,  1.0f,  1.0f, // Vertex 1 (X, Y, Z)
        -1.0f, -1.0f,  1.0f, // Vertex 2 (X, Y, Z)
         1.0f, -1.0f,  1.0f, // Vertex 3 (X, Y, Z)
         1.0f,  1.0f, -1.0f, // Vertex 4 (X, Y, Z)
        -1.0f,  1.0f, -1.0f, // Vertex 5 (X, Y, Z)
        -1.0f, -1.0f, -1.0f, // Vertex 6 (X, Y, Z)
         1.0f, -1.0f, -1.0f  // Vertex 7 (X, Y, Z)
    };

    size_t vertCount = sizeof( vertices ) / sizeof( float );
    for( size_t i = 0; i < vertCount; ++i ) {
        vertices[i] /= 2.0f;
    }

    GLubyte indices[] = {
        0, 1,
        1, 2,
        2, 3,
        3, 0,
        4, 5,
        5, 6,
        6, 7,
        7, 4,
        0, 4,
        1, 5,
        2, 6,
        3, 7
    };

    glBindBuffer( GL_ARRAY_BUFFER, vbo );
    //glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, vbo);
    glBufferData( GL_ARRAY_BUFFER, sizeof( vertices ), vertices, GL_STATIC_DRAW );

    // Create and compile the vertex shader
    GLuint vertexShader = glCreateShader( GL_VERTEX_SHADER );
    glShaderSource( vertexShader, 1, &vertexSource, NULL );
    glCompileShader( vertexShader );

    // Create and compile the fragment shader
    GLuint fragmentShader = glCreateShader( GL_FRAGMENT_SHADER );
    glShaderSource( fragmentShader, 1, &fragmentSource, NULL );
    glCompileShader( fragmentShader );

    // Link the vertex and fragment shader into a shader program
    GLuint shaderProgram = glCreateProgram();
    glAttachShader( shaderProgram, vertexShader );
    glAttachShader( shaderProgram, fragmentShader );
    glBindFragDataLocation( shaderProgram, 0, "outColor" );
    glLinkProgram (shaderProgram);
    glUseProgram( shaderProgram);

    // Specify the layout of the vertex data
    GLint posAttrib = glGetAttribLocation( shaderProgram, "position" );
    glEnableVertexAttribArray( posAttrib );
    glVertexAttribPointer( posAttrib, 3, GL_FLOAT, GL_FALSE, 0, vertices );

    // Main loop
    while(glfwGetWindowParam(GLFW_OPENED)) {

        // Clear the screen to black
        glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
        glClear( GL_COLOR_BUFFER_BIT );

        // Draw lines from 2 vertices
        glDrawElements(GL_LINES, 24, GL_UNSIGNED_BYTE, indices);

        // Swap buffers
        glfwSwapBuffers();
    }

    // Clean up
    glDeleteProgram( shaderProgram );
    glDeleteShader( fragmentShader );
    glDeleteShader( vertexShader );

    //glDeleteBuffers( 1, &ebo );
    glDeleteBuffers( 1, &vbo );

    glDeleteVertexArrays( 1, &vao );

    glfwTerminate();
    exit( EXIT_SUCCESS );
}

void initializeGLFW() {
    glfwInit();
    glfwOpenWindowHint( GLFW_OPENGL_VERSION_MAJOR, 3 );
    glfwOpenWindowHint( GLFW_OPENGL_VERSION_MINOR, 2 );
    glfwOpenWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );

    glfwOpenWindowHint( GLFW_WINDOW_NO_RESIZE, GL_TRUE );
    glfwOpenWindow( 800, 600, 0, 0, 0, 0, 0, 0, GLFW_WINDOW );
    glfwSetWindowTitle( "OpenGL" );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:51:11+00:00Added an answer on June 14, 2026 at 10:51 am

    The “default” projection is essentially glOrtho(-1, 1, -1, 1, -1, 1) with the camera at (0,0,0) looking down the -Z axis.

    Move the camera back:

    const char* vertexSource = 
        "#version 150\n"
        "in vec3 position;"
        "void main() {"
        "   gl_Position = vec4(position.x, position.y, position.z - 0.9, 1.0);"
        "}";
    

    And make your object smaller:

    float vertices[] = {
         1.0f,  1.0f,  1.0f, // Vertex 0 (X, Y, Z)
        -1.0f,  1.0f,  1.0f, // Vertex 1 (X, Y, Z)
        -1.0f, -1.0f,  1.0f, // Vertex 2 (X, Y, Z)
         1.0f, -1.0f,  1.0f, // Vertex 3 (X, Y, Z)
         1.0f,  1.0f, -1.0f, // Vertex 4 (X, Y, Z)
        -1.0f,  1.0f, -1.0f, // Vertex 5 (X, Y, Z)
        -1.0f, -1.0f, -1.0f, // Vertex 6 (X, Y, Z)
         1.0f, -1.0f, -1.0f  // Vertex 7 (X, Y, Z)
    };
    
    size_t vertCount = sizeof( vertices ) / sizeof( float );
    for( size_t i = 0; i < vertCount; ++i )
    {
        vertices[i] /= 2.0f;
    }
    

    envelope

    Complete:

    #include <GL/glew.h>
    #include <GL/glfw.h>
    #include <cstdlib>
    
    const char* vertexSource = 
        "#version 150\n"
        "in vec3 position;"
        "void main() {"
        "   gl_Position = vec4(position.x, position.y, position.z - 0.9, 1.0);"
        "}";
    
    const char* fragmentSource = 
        "#version 150\n"
        "out vec4 outColor;"
        "void main() {"
        "   outColor = vec4(1.0, 1.0, 1.0, 1.0);"
        "}";
    
    void initializeGLFW() 
    {
        glfwInit();
        glfwOpenWindowHint( GLFW_OPENGL_VERSION_MAJOR, 3 );
        glfwOpenWindowHint( GLFW_OPENGL_VERSION_MINOR, 2 );
        glfwOpenWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
    
        glfwOpenWindowHint( GLFW_WINDOW_NO_RESIZE, GL_TRUE );
        glfwOpenWindow( 800, 600, 0, 0, 0, 0, 0, 0, GLFW_WINDOW );
        glfwSetWindowTitle( "OpenGL" );
    }
    
    int main()
    {
        initializeGLFW();
    
        // Initialize GLEW
        glewExperimental = GL_TRUE;
        glewInit();
    
        // Create Vertex Array Object
        GLuint vao;
        glGenVertexArrays(1, &vao);
        glBindVertexArray(vao);
    
        // Create a Vertex Buffer Object and copy the vertex data to it
        GLuint vbo;
        glGenBuffers( 1, &vbo );
    
        float vertices[] = 
        {
             1.0f,  1.0f,  1.0f, // Vertex 0 (X, Y, Z)
            -1.0f,  1.0f,  1.0f, // Vertex 1 (X, Y, Z)
            -1.0f, -1.0f,  1.0f, // Vertex 2 (X, Y, Z)
             1.0f, -1.0f,  1.0f, // Vertex 3 (X, Y, Z)
             1.0f,  1.0f, -1.0f, // Vertex 4 (X, Y, Z)
            -1.0f,  1.0f, -1.0f, // Vertex 5 (X, Y, Z)
            -1.0f, -1.0f, -1.0f, // Vertex 6 (X, Y, Z)
             1.0f, -1.0f, -1.0f  // Vertex 7 (X, Y, Z)
        };
    
        size_t vertCount = sizeof( vertices ) / sizeof( float );
        for( size_t i = 0; i < vertCount; ++i )
        {
            vertices[i] /= 2.0f;
        }
    
        GLuint indices[] = 
        {
            0, 1,
            1, 2,
            2, 3,
            3, 0,
            4, 5,
            5, 6,
            6, 7,
            7, 4,
            0, 4,
            1, 5,
            2, 6,
            3, 7
        };
    
        glBindBuffer( GL_ARRAY_BUFFER, vbo );
        glBufferData( GL_ARRAY_BUFFER, sizeof( vertices ), vertices, GL_STATIC_DRAW );
    
        // Create and compile the vertex shader
        GLuint vertexShader = glCreateShader( GL_VERTEX_SHADER );
        glShaderSource( vertexShader, 1, &vertexSource, NULL );
        glCompileShader( vertexShader );
    
        // Create and compile the fragment shader
        GLuint fragmentShader = glCreateShader( GL_FRAGMENT_SHADER );
        glShaderSource( fragmentShader, 1, &fragmentSource, NULL );
        glCompileShader( fragmentShader );
    
        // Link the vertex and fragment shader into a shader program
        GLuint shaderProgram = glCreateProgram();
        glAttachShader( shaderProgram, vertexShader );
        glAttachShader( shaderProgram, fragmentShader );
        glBindFragDataLocation( shaderProgram, 0, "outColor" );
        glLinkProgram (shaderProgram);
        glUseProgram( shaderProgram);
    
        // Specify the layout of the vertex data
        GLint posAttrib = glGetAttribLocation( shaderProgram, "position" );
        glEnableVertexAttribArray( posAttrib );
        glVertexAttribPointer( posAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0 );
    
        // Main loop
        while(glfwGetWindowParam(GLFW_OPENED)) 
        {
            // Clear the screen to black
            glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
            glClear( GL_COLOR_BUFFER_BIT );
    
            // Draw lines from 2 vertices
            glDrawElements(GL_LINES, sizeof(indices), GL_UNSIGNED_INT, indices );
    
            // Swap buffers
            glfwSwapBuffers();
        }
    
        // Clean up
        glDeleteProgram( shaderProgram );
        glDeleteShader( fragmentShader );
        glDeleteShader( vertexShader );
    
        //glDeleteBuffers( 1, &ebo );
        glDeleteBuffers( 1, &vbo );
    
        glDeleteVertexArrays( 1, &vao );
    
        glfwTerminate();
        exit( EXIT_SUCCESS );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.