Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glGetIntegerv returning garbage value

Tags:

c++

opengl

#include<iostream>
#include"Glew\glew.h"
#include"freeGlut\freeglut.h"
using namespace std;

int main(int argc, char* argv[])
{
    GLint ExtensionCount;
    glGetIntegerv(GL_NUM_EXTENSIONS, &ExtensionCount);
    cout << ExtensionCount << endl;

    return 0;
}
  1. The output of this program is, -858993460. Why? It should return the number of extensions supported.

  2. If I remove the freeglut.h header file, the program doesn't run and throws an error message,

error LNK2019: unresolved external symbol __imp__glGetIntegerv@8 referenced in function _main

But, glGetIntegerv is inside glew.h. Why removing freeglut.h would cause an unresolved external error?

EDIT I have OpenGL 3.3 support. Using Radeon 4670 with catalyst 11.6.

like image 431
Quazi Irfan Avatar asked Dec 07 '22 20:12

Quazi Irfan


2 Answers

@mario & @Banthar yes, thanks. I have to create a context first to use the any Opengl functionality.(yes, even for Opengl 1.1 which comes default with windows.)

glGetIntegerv is not returning garbage. glGetIntegerv returns either a good value, or it does not touch the pointed to address at all. The reason why you see garbage is because the variable is not initialized. This seems like a pedantic comment, but it is actually important to know that glGetIntegerv does not touch the variable if it fails. Thanks @Damon

This bare bone works fine.

int main(int argc, char* argv[])
{
    glutInit(&argc, argv);

    glutInitContextVersion(3,3);
    glutInitContextProfile(GLUT_FORWARD_COMPATIBLE);
    glutInitContextProfile(GLUT_CORE_PROFILE);

    glutCreateWindow("Test");

    GLint ExtensionCount;
    glGetIntegerv(GL_NUM_EXTENSIONS, &ExtensionCount);
    cout << ExtensionCount << endl;

    return 0;
}
like image 179
Quazi Irfan Avatar answered Dec 09 '22 10:12

Quazi Irfan


Are you sure you have opengl 3.0? AFAIK, GL_NUM_EXTENSIONS was added in OpenGL 3.0.

like image 37
ovk Avatar answered Dec 09 '22 08:12

ovk