Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,884 questions

51,810 answers

573 users

How to draw a dot in the middle of the screen using OpenGL with FreeGLUT and GLEW in C++

1 Answer

0 votes
#include <GL/glew.h>
#include <freeglut.h>
#include <iostream>

struct Vec3 {
    float x, y, z;

    Vec3() {}

    Vec3(float _x, float _y, float _z) {
        x = _x;
        y = _y;
        z = _z;
    }
};

GLuint VBO;

static void RenderScene() { 
    glClear(GL_COLOR_BUFFER_BIT);

    glBindBuffer(GL_ARRAY_BUFFER, VBO);

    glEnableVertexAttribArray(0);

    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

    // void glDrawArrays(GLenum mode, GLint first, GLsizei count);
    glDrawArrays(GL_POINTS, 0, 1);

    glDisableVertexAttribArray(0);

    glutSwapBuffers();
}

static void CreateVertexBuffer() {
    Vec3 Vertices[1];
    Vertices[0] = Vec3(0.0f, 0.0f, 0.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)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);

    int width = 800;
    int height = 600;
    glutInitWindowSize(width, height);

    int win = glutCreateWindow("freeglut - glutCreateWindow() - Draw Dot");

    GLenum res = glewInit();
    if (res != GLEW_OK) {
        std::cout << glewGetErrorString(res);
        return 1;
    }

    GLclampf Red = 0.0f, Green = 0.0f, Blue = 0.0f, Alpha = 0.0f;
    glClearColor(Red, Green, Blue, Alpha);

    CreateVertexBuffer();

    glutDisplayFunc(RenderScene);

    glutMainLoop();
}



/*
run



*/

 



answered Jun 26, 2025 by avibootz
edited Jun 26, 2025 by avibootz
...