What am I doing Wrong (OpenGL & SDL)
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jul 4 01:06:26 PDT 2014
Sean Campbell:
> 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)
I don't know where your problem is, but you can start helping
yourself with more tidy code (because this makes it more easy to
fix) and adding some asserts on the pointers.
> float vertices[] = [
Better to use the D syntax.
> int main(string args[]){
> DerelictSDL2.load();
> DerelictGL3.load();
> SDL_Init(SDL_INIT_EVERYTHING);
Better to add a space before the { and some blank lines to
separate logically distinct pieces of your code.
Also, your main perhaps could be void (and use just empty returns
inside it).
> SDL_Window* window = SDL_CreateWindow("OpenGL", 100, 100, 800,
> 600, SDL_WINDOW_OPENGL);
Perhaps it's better to use auto here.
> glBufferData(GL_ARRAY_BUFFER, (vertices[0]).sizeof *
> vertices.length, vertices.ptr, GL_STATIC_DRAW);
Better to define a little function that computes the bytes of an
array, and call it here, it's less bug-prone.
As a first step you can assert that all the pointers that should
not be null in your program are not null. And then run a debugger.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list