0

When I attempt to generate a buffer by executing the glGenBuffer() function - no function like that is found.

Some functions are still working, and from what I see most do work, for instance the following code works perfectly:

#include <iostream>
#include <GLFW/glfw3.h>
using namespace std;

class Window_Manager
{
public:
    GLFWwindow* window;

    int Create_Window(int width, int height, const char* title) {
        if (!glfwInit()) {
            return -1;
        }

        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
        glfwWindowHint(GLFW_FOCUSED, GL_TRUE);
        
        window = glfwCreateWindow(width, height, title, NULL, NULL);
        if (window == NULL) {
            cout << "Failed to create a window! Aborting early..." << endl;
            Terminate_Window(window);
            return -1;
        }
        glfwMakeContextCurrent(window);
        
        glViewport(0, 0, width, height); 
        
        return 1;
    }
    
    void Terminate_Window(GLFWwindow* window) {
        glfwSetWindowShouldClose(window, GL_TRUE);
        glfwTerminate();
    }
};

but this code does not:

#include <GLFW/glfw3.h>
#include <Engine_Manager.h>
#include <iostream>
using namespace std;
class Shape2D
{
    int VBO;
    int Setting_Up(){
            VBO = glGenBuffer();
            return 1;
    }
};
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
IHaydot
  • 13
  • 3
  • 4
    Do you mean [`glGenBuffers`](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGenBuffers.xhtml) (plural)? – Rabbid76 Jul 07 '21 at 20:59
  • What other functions do you feel is not working as intended ? You can use glGetError if so – Prajval M Jul 07 '21 at 21:04
  • 1
    The `glGenBuffer()` of the C# helper library you used is a convenience function which uses `glGenBuffers()` internally. Replace your call to glGenBuffer() with: `glGenBuffers(1, &BVO);` and study the documentation of that function. There are at least a few more cases of this kind. – rpress Jul 07 '21 at 21:14
  • @rpress I attempted to use this call, but I still get an error for " identifier "glGenBuffers" is undefined". I don't seem to be able to use glBufferData either. – IHaydot Jul 07 '21 at 21:23
  • 1
    You might have to use GLEW in addition to GLFW. – rpress Jul 07 '21 at 21:31
  • 1
    Please edit your question to provide a [mcve] that can be used to reproduce the problem. – G.M. Jul 07 '21 at 21:31
  • As rpress suggest you need a wrangler lib like GLEW that will load the GL: funcions above OpenGL 1.0 see [complete GL+GLSL+VAO/VBO C++ example](https://stackoverflow.com/a/31913542/2521214) , you can load extentions on your own too but that is a lot of code and constants and possibility of errors ... – Spektre Jul 08 '21 at 06:24

1 Answers1

0

In addition to replacing glGenBuffer with glGenBuffers(1, &VBO) as rpress mentioned in the comments, OpenGL is a weird library in that you have to load most of the functions dynamically.

The exact details differ from platform to platform. On Windows, for example, you can use wglGetProcAddress to get pointers to desired functions.

Rather than do it manually, GLEW is an excellent library for getting OpenGL function pointers easily. Other options are documented on the OpenGL wiki.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Bernard
  • 45,296
  • 18
  • 54
  • 69
  • 1
    OpenGL is not a library. It is a specification. The API is implemented by the graphics driver. Therfore you need a loader. – Rabbid76 Jul 08 '21 at 03:59