I wrote a simple program using OpenGL, SDL 2, and GLEW. It works properly on Linux, under Wine, and on every Windows system it has been tested on. However, on another Windows computer, it is crashing as soon as it gets to glGenBuffers, even though it says OpenGL 2.1 is available. Here is the code:
#define GLEW_STATIC
#include <stdio.h>
#include <GL/glew.h>
#include <SDL2/SDL.h>
SDL_Window *window;
SDL_GLContext context;
GLuint vbo;
void Init() {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GL_LoadLibrary(NULL);
int min, max;
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,&max);
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,&min);
printf("Default OpenGL version %d.%d\n",max,min);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,1);
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,&max);
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,&min);
printf("OpenGL version %d.%d\n",max,min);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL,1);
window=SDL_CreateWindow("", 0, 0, 500, 500, SDL_WINDOW_OPENGL);
context = SDL_GL_CreateContext(window);
glewExperimental=1;
GLenum err=glewInit();
if(GLEW_OK!=err)
{
printf("Error: %s\n", glewGetErrorString(err));
}
if(window==NULL) {
printf("Could not create window: %s\n", SDL_GetError());
}
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glShadeModel(GL_FLAT);
glEnableClientState(GL_VERTEX_ARRAY);
float data[][2] = {{50,50},{100,50},{75,100}};
glGenBuffers(1,&vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
}
void Render() {
glViewport(0,0, (GLsizei) 500, (GLsizei) 500);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0f, (GLdouble) 500, 0.0f, (GLdouble) 500);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0f,0.0f,0.0f);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexPointer(2, GL_FLOAT, 2*sizeof(float), 0);
glDrawArrays(GL_TRIANGLES,0,3);
SDL_GL_SwapWindow(window);
}
int main(int argc, char **argv){
Init();
Render();
SDL_Delay(2000);
glDeleteBuffers(1,&vbo);
return(0);
}
..
.
Here is some more information I have added since initially posting this question:
- Using %p to print the address of glBindBuffer, it is 0.
- Both (GLEW_ARB_vertex_buffer_object == GL_TRUE) and (GLEW_ARB_vertex_array_object == GL_TRUE) return 0.
- glGetString(GL_RENDERER) returns "GDI Generic".
- I have also tried setting the depth size to 16, but that still doesn't work.
- The graphics card is an Nvidia 750 TI.