2

I'm using GLFW for window context creation.

I have a procs.hpp file that just loads the required opengl functions (like glCreateShader, glCreateProgram etc) using glxGetProcAddress.

The program compiles successfully but there is no point on screen when I run it. Just pink background.

Can someone point out the mistake?

#include <GLFW/glfw3.h>
#include <iostream>
#include <GL/glx.h>
#include <stdio.h>
#include "procs.hpp"

constexpr const GLchar * vertex_shader_source = 
R"(#version 450 core

    void main(){
        gl_Position = vec4(0.3, 0.3, 0.5, 1.0);
    }

)";

int a= printf("%s",vertex_shader_source);

constexpr const GLchar * fragment_shader_source = 
R"(#version 450 core
    out vec4 out_color;
    void main(){
        out_color= vec4(1,0,0,1);
    }
)"; 

int main()
{
    GLFWwindow* window;
    GLuint vertex_shader;
    GLuint fragment_shader;
    GLuint program;
    GLuint vertex_array_object;

    /* Initialize the library */
    if (!glfwInit()){
    std::cerr<<"Error initializing glfw";   
        return -1;
    }

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);  

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(1000, 800, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    vertex_shader = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vertex_shader, 1, &vertex_shader_source, nullptr);
    glCompileShader(vertex_shader);
    
    fragment_shader = glCreateShader(GL_FRAGMENT_SHADER) ;
    glShaderSource(fragment_shader,1,&fragment_shader_source,nullptr);
    glCompileShader(fragment_shader);

    program = glCreateProgram();
    glAttachShader(program,vertex_shader);
    glAttachShader(program,fragment_shader);
    glLinkProgram(program);

    // Delete the shaders as the program has them now
    glDeleteShader(vertex_shader);
    glDeleteShader(fragment_shader);

    glCreateVertexArrays(1, &vertex_array_object);
    glBindVertexArray(vertex_array_object);

    glClearColor(1,0,1,1);
    glPointSize(10.0f);
    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {   
        /* Render here */
        
        glClear(GL_COLOR_BUFFER_BIT);
        glUseProgram(program);
        glDrawArrays(GL_POINTS, 0, 1);
       
        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glDeleteProgram(program);

    glfwTerminate();
    return 0;
}

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Omkar76
  • 1,317
  • 1
  • 8
  • 22

1 Answers1

1

The point size (glPointSize) of 10.0 is not guaranteed to be provided by the OpenGL Context.
Get the point size range by retrieving the parameter GL_POINT_SIZE_RANGE:

GLfloat pointSizeRange[2];
glGetFloatv(GL_POINT_SIZE_RANGE, pointSizeRange);
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • Thanks! I tried compatibility profile and it works as expected. As of now I'm not using glew or glad to keep things simple and understand how it works without libraries. `glxGetProcAdress()` is sufficient for now. May I know from where you found that `glPointSize()` doesn't work in core profile? Can you provide the source or you know that by experience ? :) – Omkar76 Oct 10 '20 at 13:10
  • 1
    @Omkar76 From [OpenGL specification - Khronos OpenGL registry](https://www.khronos.org/registry/OpenGL/index_gl.php), compare [OpenGL 4.6 API Core Profile Specification](https://www.khronos.org/registry/OpenGL/specs/gl/glspec46.core.pdf) and [OpenGL 4.6 API Compatibility Profile Specification](https://www.khronos.org/registry/OpenGL/specs/gl/glspec46.compatibility.pdf) – Rabbid76 Oct 10 '20 at 13:11