I'm having a small problem with SDL2 and OpenGL.
I've been trying to get VBOs working (specifically ARB objects) and have thus far been unsuccessful. Through various searches around, I've found how ancient the onboard GL.h is, and opted for glew.h instead - thus allowing me to use functions past 1.1.
Whilst attempting to use glGenBuffersARB, I found that even after calling glewInit, the functions pointer was empty.
However, visualinfo reports that OpenGL is 2.1.0, and that GL_ARB_vertex_buffer_object is able to be accessed - the SDL context seems to default to Microsoft's 1.1.0, and doesn't allow me to rectify the null pointer.
I'm (sadly) using an Intel HD Graphics chipset, on an Acer Aspire 5733.
How can I get SDL to recognize the 2.1.0 on the chipset? (Or am I completely wrong in my approach to this?)
EDIT
Here's the code that was requested:
astralmain.cpp (inits SDL + OpenGL context)
bool AstralGame::onInit()
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) return false;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
if ((currWindow = SDL_CreateWindow(ASTRAL_TITLE" "ASTRAL_VERSION, 100, 100, 800, 600, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL)) == nullptr)
{
a_ErrorManager::panic("Window couldn't be created\n");
return false;
}
if ((currContext = SDL_GL_CreateContext(currWindow)) == NULL)
{
a_ErrorManager::panic("OpenGl context couldn't be created\n");
}
printf((char*)glGetString(GL_VERSION));
glewExperimental = TRUE;
glewInit();
SDL_GL_SetSwapInterval(1);
textureManager->startUp();
errorManager->startUp();
renderManager->startUp();
if (glGenBuffersARB == nullptr) printf("This entire program will not work!");
cube = new a_GL_Cube(textureManager->getTexture("astral")->texture);
//Start initting GL functions
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable(GL_TEXTURE_2D);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
cube->buildVert(1.0f);
return true;
}
a_GL3DPrimitives.cpp (builds vertices for cubes, error occurs)
void a_GL_Cube::buildVert(float size)
{
float pVt[72] = { -size, -size, size, -size, size, size, size, size, size, size, -size, size,
size, -size, size, size, -size, -size, size, size, -size, size, size, size,
size, size, size, -size, size, size, -size, size, -size, size, size, -size,
size, size, -size, size, -size, -size, -size, -size, -size, -size, size, -size,
-size, size, size, -size, size, -size, -size, -size, -size, -size, -size, size,
-size, -size, size, -size, -size, -size, size, -size, -size, size, -size, size };
float pTt[48] = { 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0,
0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0,
0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0,
0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0,
0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0,
0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 };
vboVName = 0;
vboTName = 0;
unsigned int* test = &vboVName;
glGenBuffersARB(1, &vboVName); <======= Null Pointer
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboVName);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(float)* 72, pVt, GL_STATIC_DRAW_ARB);
glGenBuffersARB(1, &vboTName);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboTName);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(float)* 48, pTt, GL_STATIC_DRAW_ARB);
delete[] pVt;
delete[] pTt;
}