What am I doing Wrong (OpenGL & SDL)

Sean Campbell via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 4 00:56:29 PDT 2014


I cannot figure out what is wrong with this code and why i keep 
getting object.error access violation. the code is simple 
tutorial code for SDL and OpenGL what am i doing wrong (the 
access violation seems to be with glGenBuffers)
The Code

import std.stdio;
import derelict.opengl3.gl3;
import derelict.sdl2.sdl;

float vertices[] = [
	0.0f,  0.5f, // Vertex 1 (X, Y)
	0.5f, -0.5f, // Vertex 2 (X, Y)
	-0.5f, -0.5f  // Vertex 3 (X, Y)
];

int main(string args[]){
	DerelictSDL2.load();
	DerelictGL3.load();
	SDL_Init(SDL_INIT_EVERYTHING);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 
SDL_GL_CONTEXT_PROFILE_CORE);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,2 );
	SDL_Window* window = SDL_CreateWindow("OpenGL", 100, 100, 800, 
600, SDL_WINDOW_OPENGL);
	SDL_GLContext context = SDL_GL_CreateContext(window);
	SDL_Event windowEvent;
	GLuint vbo;
	glGenBuffers(1, &vbo); // Generate 1 buffer
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, (vertices[0]).sizeof * 
vertices.length, vertices.ptr, GL_STATIC_DRAW);
	while (true)
	{
		if (SDL_PollEvent(&windowEvent))
		{
			if (windowEvent.type == SDL_QUIT){
				return 0;
			}else if (windowEvent.type == SDL_KEYUP && 
windowEvent.key.keysym.sym == SDLK_ESCAPE){
				return 0;
			}
			SDL_GL_SwapWindow(window);
		}
	}
	return 0;
}


More information about the Digitalmars-d-learn mailing list