0

I'm refering by my trouble to:

The OpenGL Programming Guide: The Official Guide to Learning OpenGL Version 4.3

In the 8th edition

Example 2.4 Initializing Uniform Variables in a Named Uniform Block:

I tryed to compile this Code example, but got compiling errors (as with every example of that book untill now)

After I wasn't able to find anyone else had this problem (what is strange in my eyes after I found the error source by my self), I tryed to figgure out what could be the problem.

        memcpy(buffer + offset[Scale], &scale, size[Scale] * TypeSize(type[Scale]));
        memcpy(buffer + offset[Translation], &translation, size[Translation] * TypeSize(type[Translation]));
        memcpy(buffer + offset[Rotation], &rotation, size[Rotation] * TypeSize(type[Rotation]));
        memcpy(buffer + offset[Enabled], &enabled, size[Enabled] * TypeSize(type[Enabled]));

This for lines are causing the error, where buffer is declared as: GLvoid *.

So my question is: Why they try to do pointer arithmetic on a void pointer (As I'm guessing, thats what GLvoid * is)?

And what I probably have to cast it to, that it gets teh right length memcpyed?

as I'm new to openGL and can't get really get the context of that (300 lines) example to get by my self what the GLvoid * is working with.

Can any one who knows the book, or at least the example tell me what I had to cast the Dst part of memcpy to? Or tell me what else I'm maybe doing wrong and how to solve it?

dhein
  • 6,431
  • 4
  • 42
  • 74
  • What are the exact errors you are getting? Try also compiling with e.g. clang, its error message will be similar, but might just provide that word or phrase that gives you a better hint on how to attack this problem. – rubenvb Feb 17 '15 at 20:20
  • its simply: "1>c:\users\dhein\documents\visual studio 2010\projects\shadergettingstarted\shadergettingstarted\shadergettingstarted.cpp(199): error C2036: 'GLvoid *' : unknown size " – dhein Feb 17 '15 at 20:20
  • Note this may not have anything to do with your current problem... If you're using the Visual Studio OpenGL headers, you have version 1.1 at your disposal. That sucks, but yeah, reality is a... euhm... not nice. You'll need some helper library that gets you up-to-date functionality at runtime. See e.g. [this tutorial](http://www.swiftless.com/tutorials/opengl4/1-opengl-window.html) which uses GLEW for this purpose (scroll down and grab the pdf, the code on the website is missing all `` after the `#include` statements... – rubenvb Feb 17 '15 at 20:25
  • @Axalo: yep as I stated in my OP, thats the problem. – dhein Feb 17 '15 at 20:26
  • @rubenvb: I'm using glut and glew, as they are part of the headers especially provided by the book for tutorial purposes. So It is not expected they missed something in it, what they use in their examples (but by the samples up to now, It wouldn't suprise me anymore.) – dhein Feb 17 '15 at 20:26
  • Ah ok, nevermind then :) – rubenvb Feb 17 '15 at 20:29

1 Answers1

1

You cannot add to a void pointer since it's size is undefined.
Casting it to char * should solve your issue.

Axalo
  • 2,953
  • 4
  • 25
  • 39
  • I know that I can't. Thats what I already said in my original post. But my question is about, any one knows, the kontext of that example, and what they expect. Can you ground your suggestion, of "They wan't to operate Byte wise in that sample"? – dhein Feb 17 '15 at 20:29
  • Are you sure `buffer` is not of type `char *`? If so the book is wrong as you [must not add to a `void *`](http://stackoverflow.com/questions/3523145/pointer-arithmetic-for-void-pointer-in-c). – Axalo Feb 17 '15 at 20:33
  • yep im sure, and yep the book IS wrong. just btw. I didn't had one sample code in it up to now, where their wasn't significant errors within. So that isn't a suprise :D And thats also why I ask especially for someone who can help me with the sample code, and not with the given error. As I know why the error appears, I just don't know what the authors where intended to do. – dhein Feb 17 '15 at 20:38
  • Currentyl with char * cast it compiles but crashes. But this could also be caused by other errors of their example. currently i'm dbeugging it. I'll let you know. – dhein Feb 17 '15 at 20:39
  • Your guess was right... like 80 pages later, they drop a note about GLvoid is expected to be "Basic-machine units, i.e. Bytes" What a glorious book ^^ – dhein Feb 18 '15 at 16:24