Johnathon332
Posts: 10
Joined: Thu Aug 02, 2012 10:26 pm

Getting started

Thu Aug 02, 2012 11:01 pm

Hi guys, I'm pretty new to linux so not really sure on how to get started on OGLES. Most of my projects in OGLES have been on windows. I was wondering if someone can tell me about the makefile and how it works also what libraries do you need to include to work with OGLES.

Thank you.

arturo777
Posts: 28
Joined: Sat Mar 24, 2012 10:02 am

Re: Getting started

Fri Aug 03, 2012 8:03 am

I'd suggest having a look at the triangle2 sample located here:

https://github.com/raspberrypi/firmware ... _triangle2

It is also preinstalled on the pi, I think in /opt/vc/src/hello_pi/hello_triangle2. To build this and the other samples in hello_pi, check out:

https://github.com/raspberrypi/firmware ... _pi/README

I guess you could adapt the main makefile for other projects too :)

Johnathon332
Posts: 10
Joined: Thu Aug 02, 2012 10:26 pm

Re: Getting started

Fri Aug 03, 2012 2:05 pm

Hi, Thank you for your response is it possible you could explain to me how to makefile is composed in the demo's? Sorry for being a noob but I'm quite new to Linux.

Thanks again.

Johnathon332
Posts: 10
Joined: Thu Aug 02, 2012 10:26 pm

Re: Getting started

Fri Aug 03, 2012 3:42 pm

There also seems like there's an awful lot of code just to set up a window

arturo777
Posts: 28
Joined: Sat Mar 24, 2012 10:02 am

Re: Getting started

Mon Aug 06, 2012 10:21 am

That's true, there is quite a lot of code to do something simple :shock:
Actually, I mixed up my samples a bit, hello_triangle is simpler! I'm also a complete beginner, but I'll try to walk you through what I have learnt so far ;)

Looking at the makefile in hello_triangle, it basically sets the specifics of the project, namely the object files generated and the name of the output binary. What is really important is the fourth line, that includes the standard makefile for all of the hello_pi samples. It is this makefile, Makefile.include, that provides all of the information about the libraries etc. and how to compile with them. You can use Makefile.include as is.

What I would do, is copy the hello_triangle directory somewhere and then start playing around with the copie. You'll need to change that fourth line in Makefile to make sure it can find Makefile.include. Also if you create more .c files that need to be linked together, or change their names, you'll need to edit OBJS, and maybe even BIN, if you'd like the output binary to be called something else.

So, now looking at the source code, starting with the main function at the end of the file. Basically, it does some initialization and then starts a loop which repeatedly moves and draws the cube. What is important, is the call to bcm_host_init: this is specific to the pi, and must be called before any OpenGL function (or maybe it should be called in any program?).

The init_ogl function is almost entirely for setting up a native window: the first half is concerned with the egl side of things, the second half with wiring it up to the vc side of things. The function finishes with code to clear the newly created surface. Notice also that all of the specifics are saved in the custom CUBE_STATE_T structure to make it easy to pass them around.

The remaining functions do pretty much what they say they do, although they are not really super simple: setting the projection, loading the textures etc.... I'm still studying them myself. To continue with simple stuff, I'm working through the basics presented in OpenGL® ES 2.0 Programming Guide, http://opengles-book.com/, in particular the chapter 2 sample, which you can find here:

http://code.google.com/p/opengles-book- ... Triangle.c

Johnathon332
Posts: 10
Joined: Thu Aug 02, 2012 10:26 pm

Re: Getting started

Mon Aug 06, 2012 11:09 am

Hey, thank you for your walkthrough the CUBE_STATE_T structure has some EGL code in it too...I would have thought you would just put it in a seperate structure as it makes readability more clear? or is it needed even for the actual GLES2.0 code. Sorry im not very good at explaining things

jmacey
Posts: 135
Joined: Thu May 31, 2012 1:05 pm

Re: Getting started

Mon Aug 06, 2012 7:47 pm

I wrapped a lot of this code up into a C++ class to make it easier, you can see my design and explanation here

http://jonmacey.blogspot.co.uk/2012/06/ ... class.html and http://jonmacey.blogspot.co.uk/2012/06/ ... onfig.html

Once you have the basic window, most OpenGL ES demos should work ok, however things like image loading for textures would need some extra code (I use ImageMagic to load the image data)

Jon

Return to “OpenGLES”