PDA

View Full Version : Can't find functions like "glBindFramebuffer"



BlendBand
04-02-2017, 02:00 AM
I have freeglut 3.0.0, eclipse, TDM-GCC-64, mingw, and it works well for certain standard gl functions. I can't use glBindFramebuffer. It says "error: 'glGenFramebuffers' was not declared in this scope". How can I fix this?

GClements
04-02-2017, 04:16 AM
You may need a more up-to-date version of <GL/glext.h>, which you can get from here (https://www.khronos.org/registry/OpenGL/index_gl.php#headers).

BlendBand
04-02-2017, 05:35 AM
You may need a more up-to-date version of <GL/glext.h>, which you can get from here (https://www.khronos.org/registry/OpenGL/index_gl.php#headers).

Downloaded it and replaced my "GL/glext.h", restarted eclipse and buildt. No difference. Should I include something more than "#include <GL/glut.h>". Btw I have: "opengl32" "glu32" "freeglut" in libraries.

Dark Photon
04-02-2017, 11:44 AM
You may have to modify your include path to ensure that it picks up the correct glext.h file. Find out where it's currently pulling in glext.h by turning on writing preprocessor output. If you're using MSVS, take a look at this (https://stackoverflow.com/questions/8978997/how-can-i-see-the-output-of-the-visual-c-preprocessor).

Note that in your code, you'd normally do this:


#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glut.h>


The #define tells gl.h to pull in glext.h automatically.

However, if you're using GLEW (an OpenGL extension loader), this should be sufficient:


#include <GL/glew.h>
#include <GL/glut.h>

BlendBand
04-06-2017, 03:07 AM
I have deleted my old TDM MingGW setup and started fresh with MingGW.

I get the same problem with glew. I have replaced the old glext.h that comes with the latest version of MingGW so my current glext.h does contain:

GLAPI void APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer);

I have updated my OpenGL AMD driver. Using "OpenGL extension viewer" I can see that I have: OpenGL 4.4

I am linking to "OpenGL32" and "glew32", "glew32s" in:

"C:\OpenGL\glew-2.0.0\lib\Release\Win32"

BlendBand
04-06-2017, 03:53 AM
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glext.h>

using namespace std;

int main(int argc, char** argv){

GLuint framebuffer = 1;
glBindFramebuffer(GL_ELEMENT_ARRAY_BUFFER, framebuffer);
}

and I get: ../main.cpp:17: undefined reference to `glBindFramebuffer8'

or with glew:


#define GL_GLEXT_PROTOTYPES

#include <GL/glew.h>

using namespace std;

int main(int argc, char** argv){

GLuint framebuffer = 1;
glBindFramebuffer(GL_ELEMENT_ARRAY_BUFFER, framebuffer);
}

../main.cpp:17: undefined reference to `_imp____glewBindFramebuffer'

john_connor
04-06-2017, 05:01 AM
if you use GLEW, together window creation lib like GLFW, you have to include glew.h before you include for example glfw3.h, otherwise you'' get some errors. another thing is that you can link to glew statically or dynamically, that is the latter needs additionaly a .dll file. but if you want to avoid that .dll "uglyness", and you want to link statically, you have to define GLEW_STATIC before you include glew.h:

static linking:


#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>

... here your code ...

the order in which you declare the libraries you want to link to matters also, e.g. if you link to "opengl32" before the other libs, you get linking errors like:

lib\libSOIL.a(SOIL.o):SOIL.c|| undefined reference to `glTexImage2D@36'
thats at least true for codeblocks + minGW

by the way: thats an error

glBindFramebuffer(GL_ELEMENT_ARRAY_BUFFER, framebuffer);
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBindFramebuffer.xhtml
and you first have to create a framebuffer

GClements
04-06-2017, 05:11 AM
and I get: ../main.cpp:17: undefined reference to `glBindFramebuffer8'

That's a linking issue, not compilation (and I suspect there should be an @ in there, i.e. "glBindFramebuffer@8")

On Windows, opengl32.dll only exports the OpenGL 1.1 API. If you want to use any function which was added in a later version or in an extension, you have to get a function pointer from the driver using wglGetProcAddress(). Or use e.g. GLEW or GL3W, which exist precisely to do this for you.



../main.cpp:17: undefined reference to `_imp____glewBindFramebuffer'
This is also a linking problem. It usually arises from trying to use libraries built for MSVC with MinGW. Either build GLEW from source with MinGW, or just build GLEW itself into your program (i.e. add glew.c as a source file and #define GLEW_STATIC before including glew.h).

BlendBand
04-06-2017, 05:53 AM
Thank you guys "define GLEW_STATIC" did the trick!

Yes you are right it is suppose to be an a) there. I couldn't post with it in the text.

EDIT:

Maybe not though...I can build but it might not work porperly. I have built GLEW myself now and I am wondering why eclipse don't want to auto-complete/show suggestion for glBindFrameBuffer.

I built GLEW with


$ mingw32-make
$ mingw32-make install
$ mingw32-make install.all

This crashes:



#define GL_GLEXT_PROTOTYPES
#define GLEW_STATIC

#include <GL/glew.h>
#include <GL/freeglut.h>

using namespace std;

int main(int argc, char** argv){


//glutInit(&argc, argv);

GLuint FramebufferName = 0;
glGenFramebuffers(1, &FramebufferName);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);


}


Linking looks like:

g++ "-LC:\\OpenGL\\glew-2.0.0\\lib" "-LC:\\OpenGL\\freeglut-3.0.0-Cmade\\lib" -o Ordentligt.exe main.o -lglew32 -llibglew32 -lfreeglut_static -lglu32 -lfreeglut.dll -lglew32.dll -lOpenGL32

The files are:

libglew32.dll.a, libglew32.a, libfreeglut_static.a, libfreeglut.dll.a

john_connor
04-06-2017, 07:00 AM
int main(int argc, char** argv){


//glutInit(&argc, argv);

GLuint FramebufferName = 0;
glGenFramebuffers(1, &FramebufferName);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);


}


linking / compiling aside, you dont have a window + opengl context on which you can work. so the first thing would be to create a window + opengl context. glew doesnt do that for you, other libs like GLFW do that:
http://www.glfw.org/documentation.html


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

after that, you can be sure that there is a window + opengl context. but to have access to all the opengl functions (which are function pointers), glew needs to initialized (it queries all these GL function pointers for you):


/* Initialize GLEW */
if (glewInit() != GLEW_OK)
{
glfwTerminate();
return -2;
}

after that, you can be sure that there is a window + opengl context + all the GL functions to work with.
https://sites.google.com/site/john87connor/home/1-1-creating-a-window

you still dont know the GL version / GLSL version etc of the context, you can query that on you own:
https://www.khronos.org/opengl/wiki/Get_Context_Info
https://sites.google.com/site/john87connor/home/1-2-graphics

if you're using glut or freeglut, try this:


#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

void renderScene(void) {

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glBegin(GL_TRIANGLES);
glVertex3f(-0.5,-0.5,0.0);
glVertex3f(0.5,0.0,0.0);
glVertex3f(0.0,0.5,0.0);
glEnd();

glutSwapBuffers();
}

int main(int argc, char **argv) {

// init GLUT and create Window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("Lighthouse3D - GLUT Tutorial");

// register callbacks
glutDisplayFunc(renderScene);

// enter GLUT event processing cycle
glutMainLoop();

return 1;
}

BlendBand
04-06-2017, 07:31 AM
Thanks! It seems to work now. (although not the autocomplete/suggestions on e.g glBindFrameBuffer in eclipse):

This is the test code:




#define GL_GLEXT_PROTOTYPES
#define GLEW_STATIC

#include <stdio.h>

#include <GL/glew.h>
#include <GL/freeglut.h>

using namespace std;

void display(){

//glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();

}

int main(int argc, char** argv){



glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(640, 480);
glutCreateWindow("test");

glutDisplayFunc(display);

glClearColor(1,0,0,1);

if (glewInit() != GLEW_OK)
{
return -2;
}

GLfloat g_vertex_buffer_data[] = {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
};

GLuint vertexbuffer;

glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);

glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);

glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);

glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);

glutMainLoop();

}