edbird
Posts: 50
Joined: Wed Jun 25, 2014 1:11 pm

Re: opengl toolkit/library for RPi

Tue Jul 29, 2014 6:59 pm

Dude I don't see anything abrasive or not child friendly in that post, and I also don't see the pros of diluting this discussion with chatter about whether my posts meet the rules or not. If I was someone trying to fix this problem in the future I would want all the information presented to me clearly and quickly. At the moment this discussion is preventing that so I think it would be best if we stayed on topic.

edbird
Posts: 50
Joined: Wed Jun 25, 2014 1:11 pm

Re: opengl toolkit/library for RPi

Tue Jul 29, 2014 7:12 pm

Okay so I kind of fixed the previous problem by using the makefile instead... Not sure exactly how I fixed it though as I don't fully understand the changes I made.

Now I have some more errors, such as:

error: success was not declared in this scope

This is from the line:

success = graphics_get_display_size(...)

There are many more similar errors.

My thought process is either:

1: There is a file somewhere where these symbols are defined in which case I have not included it.
2: These should be defined in main, for example the code should be something like "int success = graphics_get_display_size(...)" in which case benosteen did not fully write out all the code required.

In either case, although apparently no one wants to hear this, I say again about this not being properly or fully explained, which it clearly is not. But what am I to do? If I assume these symbols should be of the type "int" I might be able to compile this program, but how am I to know that this wont result in problems in the future? So I could try putting int in front of everything, but that is clearly a stupid thing to do! I mean come on guys, how is the average person supposed to be able to follow this?

User avatar
Paeryn
Posts: 2966
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: opengl toolkit/library for RPi

Tue Jul 29, 2014 11:15 pm

edbird wrote:Okay so I tried putting that esUtil.c file in my main.cpp file's directory, and attempted to compile using:

g++ main.cpp esUtil.c -o main.out -I/opt/vc/include -L/opt/vc/lib

Get a lot of errors including invalid conversions of data-types, so I'm guessing the original author of the code was being lazy when he wrote the code as well as the post, but these are less critical than the fatal errors:
He isn't being lazy, you're compiling C code as C++. They are only errors in the sense that g++ is defaulting to flagging implicit type conversions between signed and unsigned types as errors. If you compile with gcc then you won't get them (or pass -fpermissive to g++, then they will be just given as warnings and not prevent compilation).
edbird wrote:vchost_config.h No such file or directory
You need to pass -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux to gcc/g++

If you are using the esUtil.c code as it is you will also need to pass -DRPI_NO_X to gcc/g++ to make sure it doesn't try to compile the X11 code.
Also, don't forget to actually link in the libraries with -lGLESv1_CM -lEGL -lbcm_host change GLESv1_CM to GLESv2 if you're using ES2.0. Actually, I think the linker will automagically pull in the rest as long as you link in at least the GLES one (just tested it and it didn't complain), but I always explicitly give them.

So your compile command should be something along the likes of

Code: Select all

g++ -DRPI_NO_X -fpermissive -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -o main.out main.cpp esUtil.c -lGLESv1_CM -lEGL -lbcm_host -L/opt/vc/lib 
[Just seen your further post as I was previewing what I'd written]
[Edit] See my next post below for why I could see it defined but you couldn't.

success is declared at the start of WinCreate, which is the function it is used in. I can't see it used elsewhere in esUtil.c

Code: Select all

EGLBoolean WinCreate(ESContext *esContext, const char *title) 
{
   int32_t success = 0;
I've compiled the esUtil.c file without any errors. I've just compiled all the examples that are given with no errors, and they run (although I can't see any graphical output as my RPi isn't connected to a display at the moment).
Last edited by Paeryn on Wed Jul 30, 2014 1:53 pm, edited 1 time in total.
She who travels light — forgot something.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26660
Joined: Sat Jul 30, 2011 7:41 pm

Re: opengl toolkit/library for RPi

Wed Jul 30, 2014 10:16 am

edbird wrote:Dude I don't see anything abrasive or not child friendly in that post, and I also don't see the pros of diluting this discussion with chatter about whether my posts meet the rules or not. If I was someone trying to fix this problem in the future I would want all the information presented to me clearly and quickly. At the moment this discussion is preventing that so I think it would be best if we stayed on topic.
In the spirit of completeness I've just re-read all your posts above.

If you seriously think you are not being abrasive, then you need to think again. At least three of your posts are abrasive according to mine (and other mods) standards. So, please, as I asked before, keep it polite.

You may think this post of 'off topic'. It isn't. It's also not preventing your question being answered; in fact, I hope it will help in getting your question answered, by ensuring that future posts are polite and non-abrasive. Posts like that get answered. Rude abrasive ones don't. It's your call. No further comments on this please (that's to all), I will delete further posts that are not connected with answering the question.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

User avatar
Paeryn
Posts: 2966
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: opengl toolkit/library for RPi

Wed Jul 30, 2014 1:42 pm

Ah, just looking through the X11 code, WinCreate doesn't have the success variable declared in there, only in the RPi version, and the code snippet on the webpage doesn't declare it (it is declared in the line above where the snippet starts), but it is in the esUtil.c file under the Raspi/Common directory (which has all the modifications already made). I wonder if some of the other errors you said you were getting (but didn't specifically name) were to do with compiling the X11 parts (which are not used on the RPi).
She who travels light — forgot something.

edbird
Posts: 50
Joined: Wed Jun 25, 2014 1:11 pm

Re: opengl toolkit/library for RPi

Wed Jul 30, 2014 5:18 pm

Okay thanks, I feel like I'm getting some successes with this at last. Got some more errors... I'm guessing once 1 more step is completed these will be fixed. I will type them all out for you. (You already saw one of them.)

in main...
success was not declared in this scope (again)
some invalid conversion errors even though I passed -fpermissive??
initializing arguments 2 and 3 of graphics_get_display_size - again strange since I passed -fpermissive??
vc_dispman_update_start was not declared
esContext, display, surface and config undeclared
hWnd, context undeclared in this scope
warning: -fpermissive is valid for C++ but not C -- is this why the -fpermissive flag isn't working?

in function WinCreate ...
error FALSE undeclared
same again for TRUE

in function esRegisterDrawFunc, and 2 other functions esRegisterUpdateFunc, esRegisterKeyFunc
warning: assignment for incompatible pointer type

Thanks for the help so far.

Going back to the mod's point for just a sec, sorry if you interpreted what I said as abrasive, as I said before it was not my intention for you to interpret it that way. As I said before putting an internet connection between 2 people can cause problems. I guess this is just one of those times.

User avatar
Paeryn
Posts: 2966
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: opengl toolkit/library for RPi

Wed Jul 30, 2014 8:40 pm

edbird wrote:Okay thanks, I feel like I'm getting some successes with this at last. Got some more errors... I'm guessing once 1 more step is completed these will be fixed. I will type them all out for you. (You already saw one of them.)

in main...
Why are these in main? The first lot are related to things that should be in WinCreate(). The webpage didn't make it clear that that big chunk of code was the replacement for WinCreate. Have you looked at the code from the Raspi/Common directory of the source code? It already has all the modifications (more than what is given on the webpage) required.
edbird wrote:some invalid conversion errors even though I passed -fpermissive??
warning: -fpermissive is valid for C++ but not C -- is this why the -fpermissive flag isn't working?
Yes, -fpermissive is only for C++, it basically relaxes some of C++'s strictness by downgrading certain errors into warnings.
edbird wrote:success was not declared in this scope (again)
success is only referenced twice (three if you count where it's initialised),
At the start of WinCreate() it should be declared with the type int32_t

Code: Select all

  int32_t success = 0;
The only two lines of code that reference success are the first two lines of code after the variable declarations, if you've got the declaration above then these shouldn't cause problems.
edbird wrote:initializing arguments 2 and 3 of graphics_get_display_size - again strange since I passed -fpermissive??
If you're compiling as C++ then -fpermissive should cover it. As C it shouldn't be complaining, or at most a warning (unless you have all warnings set as errors with the option -Wall or the specific warning that is triggering this -Wpointer-sign).
Arguments 2 and 3 to graphics_get_display_size() should be unit32_t *, but the code given declares those variables as int (so the function is being passed pointers to signed ints rather than pointers to unsigned ints). You could change the declaration of both display_width and display_height to be either unsigned int or uint32_t, that should clear the complaint.
The problem isn't in that it's assigning between a signed int and an unsigned int - even C++ lets you do that, but it's the conversion of a "pointer to a signed int" to a "pointer to an unsigned int", C++ is strict on not allowing conversions of "pointer to something" into "pointer to something else" without making you work since it can break things in a big way. In this case it's pretty much safe, but the compiler can't know that.
edbird wrote:vc_dispman_update_start was not declared
That should be vc_dispmanx_update_start note the x at the end of dispman.
edbird wrote:esContext, display, surface and config undeclared
esContext is used as the name of a variable in a lot of the function declarations, in the whole of esUtil.c these are the only places where it is declared. It should be of type ESContext *.
display, surface & config are all from CreateEGLContext and should be

Code: Select all

  EGLDisplay display;
  EGLSurface surface;
  EGLConfig config;
edbird wrote:hWnd, context undeclared in this scope
hWnd is the first parameter of CreateEGLContext and has the type of EGLNativeWindowType.
context is declared in the same function as having the type EGLContext
edbird wrote:in function WinCreate ...
error FALSE undeclared
same again for TRUE
The only places I can see FALSE and TRUE used is in the X11 version of WinCreate(), which it appears from what you've written that the stuff you added (referred to earlier as being in main) should have been used as the replacement for WinCreate(). Even so, they are #defined in esUtil.h to be 0 and 1.
edbird wrote:in function esRegisterDrawFunc, and 2 other functions esRegisterUpdateFunc, esRegisterKeyFunc
warning: assignment for incompatible pointer type
Not sure about these, I assume it's complaining about the pointers to functions but the definitions look fine. That code hasn't changed from the X11 version to the RPi version.
The variables being assigned to is (for the drawfunc) of type void (ESCALLBACK *drawFunc)(struct _escontext *) and it's being passed a variable of type void (ESCALLBACK *drawFunc)(ESContext *). ESContext is defined in esUtil.h as a typedef for struct _escontext {...} so there shouldn't be any confict.
edbird wrote:Thanks for the help so far.
That's okay.
She who travels light — forgot something.

edbird
Posts: 50
Joined: Wed Jun 25, 2014 1:11 pm

Re: opengl toolkit/library for RPi

Fri Aug 01, 2014 8:00 pm

Ahhh, this is a never ending cycle... Thanks for those pointers, a lot of things are making a lots more sense now as I can see where some of these variables etc come from.

However there's still 1 more error...

Inside WinCreate() (Which I found was inside esUtil.c, by the way - managed to find that one at least...)
graphics_get_display_size was not declared in this scope

Anyone know how to fix this one??

edbird
Posts: 50
Joined: Wed Jun 25, 2014 1:11 pm

Re: opengl toolkit/library for RPi

Fri Aug 01, 2014 8:05 pm

Also I should probably ask sooner rather than later... What goes in main() ?? An intelligent guess might be a call to winCreate() after calling bcm_init().

User avatar
Paeryn
Posts: 2966
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: opengl toolkit/library for RPi

Sat Aug 02, 2014 9:23 pm

edbird wrote:Inside WinCreate() (Which I found was inside esUtil.c, by the way - managed to find that one at least...)
graphics_get_display_size was not declared in this scope

Anyone know how to fix this one??
graphics_get_display_size() is declared in bcm_host.h which you should have #included.
edbird wrote:Also I should probably ask sooner rather than later... What goes in main() ?? An intelligent guess might be a call to winCreate() after calling bcm_init().
Yes, you need to create and initialize the esContext, create the window, setup the Draw and Update functions, run the main loop, then shutdown.

The example code from the book goes like this:

Code: Select all

int main (int argc, char *argv[])
{
  ESContext exContext;
  UserData  userData;

  esInitContext(&esContext);
  esContext.userData = &userData;

  esCreateWindow(&esContext, "Simple Texture 2D", 320, 240, ES_WINDOW_RGB);

  if (!Init(&esContext))
    return 0;

  esRegisterDrawFunc(&esContext, Draw);
  esRegisterUpdateFunc(&esContext, Update);

  esMainLoop(&esContext);
  ShutDown(&esContext);
}
All the functions beginning with es come from esUtil.c, Init, Draw, Update and ShutDown are your own functions.
esMainLoop loops calling Update, Draw and eglSwapBuffers.
bcm_host_init() is called in esInitContext(), that way you only need to include bcm_host.h in esUtil.c, not in your main file.
She who travels light — forgot something.

edbird
Posts: 50
Joined: Wed Jun 25, 2014 1:11 pm

Re: opengl toolkit/library for RPi

Sun Aug 03, 2014 11:03 am

Interesting, so my guess is that all the opengl (opengl es) code for drawing stuff goes inside the draw function (pretty obvious) and then all the non-drawing specific code goes in the update function?

Does the main loop (esMainLoop) just call these 2 functions one after another continually? What should the function look like? IE: Does it return void and take no arguments?

Also I'm guessing I need to setup my variables "world objects or varaibles" to be global so that I can access them from all these functions.

Last few issues then...

- UserData was not declared in this scope (I have included bcm_host.h and esUtil.h)
- Issues with the Draw Init and ShutDown functions because I haven't written them yet. Guessing that they all return void and take no arguments? Except for ShutDown which should take a pointer to an ESContext type?

Then once those 2 are sorted, hopefully this thing will compile...

edbird
Posts: 50
Joined: Wed Jun 25, 2014 1:11 pm

Re: opengl toolkit/library for RPi

Sun Aug 03, 2014 11:08 am

Just tried those initial thoughts for the 4 functions, and they're working too. Just UserData to fix now, 1 more error

User avatar
Paeryn
Posts: 2966
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: opengl toolkit/library for RPi

Sun Aug 03, 2014 12:53 pm

edbird wrote:Interesting, so my guess is that all the opengl (opengl es) code for drawing stuff goes inside the draw function (pretty obvious) and then all the non-drawing specific code goes in the update function?

Does the main loop (esMainLoop) just call these 2 functions one after another continually? What should the function look like? IE: Does it return void and take no arguments?

Also I'm guessing I need to setup my variables "world objects or varaibles" to be global so that I can access them from all these functions.

Last few issues then...

- UserData was not declared in this scope (I have included bcm_host.h and esUtil.h)
- Issues with the Draw Init and ShutDown functions because I haven't written them yet. Guessing that they all return void and take no arguments? Except for ShutDown which should take a pointer to an ESContext type?

Then once those 2 are sorted, hopefully this thing will compile...
Look at the chapter examples from https://github.com/benosteen/opengles-b ... ster/Raspi, they show you how to use the framework.
It's not really a good idea to create loads of global variables. That's what UserData is used for in here, you create a struct that contains all the variables which need passing around, the address of UserData is put into the esContext variable which is already passed to all the es* functions.
You need to define UserData yourself, you can put whatever you want in it. It's type in ESContext is a void* so you cast it to whatever you define it to be.

Draw will be passed an ESContext* as a parameter and returns void, Update will be passed two parameters, ESContext* and float. The float will contain the number of seconds since the last frame.

Code: Select all

void Draw( ESContext *esContext );
void Update( ESContext *esContext, float deltaTime );
Init and Shutdown are separate from the framework, you can define and use them however you want. In the examples they both take ESContext* as a parameter since they need the variables in it, and Init returns an int to signal whether the initialization succeeded.
She who travels light — forgot something.

User avatar
PeterO
Posts: 5879
Joined: Sun Jul 22, 2012 4:14 pm

Re: opengl toolkit/library for RPi

Sun Aug 03, 2014 4:57 pm

In my experience the whole "toolkit" architecture from the book examples makes the whole thing seem much more complicated that it really needs to be.

If you strip is all back to just the essentials it is much easier to see what is going on.

Look in http://www.peteronion.org.uk/OpenGLES/ for some examples.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

edbird
Posts: 50
Joined: Wed Jun 25, 2014 1:11 pm

Re: opengl toolkit/library for RPi

Mon Aug 04, 2014 4:54 pm

Good news, finally, it does compile, however bad news, it does not link...

In esUtil.c (.text + 0x344) - undefined references to:]

XNextEvent, XLookupString, XPending

So my guess would be that we need to link with the XWindow system... However we passed -DRPI_NO_X, which confuses me... Is there a different X which should be linked?

User avatar
Paeryn
Posts: 2966
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: opengl toolkit/library for RPi

Mon Aug 04, 2014 7:49 pm

edbird wrote:Good news, finally, it does compile, however bad news, it does not link...

In esUtil.c (.text + 0x344) - undefined references to:]

XNextEvent, XLookupString, XPending

So my guess would be that we need to link with the XWindow system... However we passed -DRPI_NO_X, which confuses me... Is there a different X which should be linked?
Those functions are called in userInterrupt in the X11 part, you should have a replacement for that function

Code: Select all

GLboolean userInterrupt(ESContext *esContext)
{
    // Ctrl-C for now to stop
    
    return GL_FALSE;
}
This function is called as part of the while loop in esMainLoop and determines when the program should stop. The original code is set up so the loop will be terminated when the window is closed, but as the RPi version doesn't have a window manager the replacement code for the RPi doesn't do anything, instead it relies on the behaviour of Ctrl-C stopping the program.
She who travels light — forgot something.

edbird
Posts: 50
Joined: Wed Jun 25, 2014 1:11 pm

Re: opengl toolkit/library for RPi

Tue Aug 05, 2014 12:11 pm

Thanks a lot for your help, it now compiles and runs and I get a black screen. (As expected.)

I now have a vague idea about where to put my drawing code, how to handle keyboard events and now to execute per-loop code. Hopefully I will now be able to add the stuff from the OpenGL book to get a triangle to show.

I will try and get a better understanding of the whole process to get this working, and then I will write a tutorial, perhaps on wikihow as I haven't got a better idea of where to put one. As promised, I will cite yourself as the person who helped get all of this working, and I will check through the earlier posts to see if anyone else contributed too, can't remember what happened when right now.

If you have a better suggestion for where I should put a tutorial on this, let me know. (Not youtube, I'm not making a video on it.)

Thanks again, hopefully you wont hear anymore from me about errors.

edbird
Posts: 50
Joined: Wed Jun 25, 2014 1:11 pm

Re: opengl toolkit/library for RPi

Tue Aug 05, 2014 2:25 pm

So, I tried out the triangle example, and the first thing I noticed was that the screen was flickering at about 60 Hz.

2 images appeared, firstly my desktop background, and secondly the triangle image.

This was really trippy and kind of not very pleasant to look at, and also it's not what you would expect to see usually, so I would rather it just not happen... Anyway I removed the swap buffers call at the end of the draw function because I figured it was probably a double buffering issue.

I was surprised to see that I could still see my triangle, but now it didn't flicker.

Turns out that there is a call to swap the buffers ALREADY inside esUtil.c... Inside the esMainLoop function, so you don't want to add another in the drawing function.

So yeah for anyone in the future copying the book, remove that line at the end of your drawing routine.

User avatar
Paeryn
Posts: 2966
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: opengl toolkit/library for RPi

Tue Aug 05, 2014 2:47 pm

I'm glad you've got it up and running so far.

Best advice I can give is don't be afraid to experiment and only make small changes at a time so it's easier to figure out where things have gone wrong.

Hope you have fun with it, and if you do get stuck we'll be happy to help.
She who travels light — forgot something.

Return to “OpenGLES”