jonshouse
Posts: 41
Joined: Sat Aug 11, 2012 7:10 pm

2d lines using GLES2?

Fri Aug 07, 2015 2:30 pm

What I am tring to do is port a program that draws wire frame annimation (currently into the framebuffer) to GLES2, the snag is I know very little about GL !

My current code (plain C) draws a number of lines using a function like this

Code: Select all

void plotline (unsigned short int *framebuffer,int x1, int y1, int x2, int y2, unsigned short int color)
x,y origin to x,y destination in 16 bit 565 color.


I want to do the same sort of thing in GL but all the demos are find seem vastly over complicated with textures and spinning viewing angles etc, can anyone point me at a simple 2d annimation demo that I can crib from ?

I want to draw N lines in the form x1,y1 to x2,y2 in color C, then re-draw them in different poistions for each frame :-)

Thanks,
Jon

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

Re: 2d lines using GLES2?

Fri Aug 07, 2015 2:39 pm

I'm sorry you aren't going to like this, but you really need to follow and understand some of the GLES2 tutorials that you have found. GLES2 is not simple, it's very different from your existing graphics code, and you won't just be able to easily convert your existing code.

It takes a considerable time to learn GLES if you've not done anything like it before. Personally I found this book to be the most useful thing in learning openGL ES. http://www.opengles-book.com/es2/index.html

When I get home I'll see if I have any simple demo code that draws lines.

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

jonshouse
Posts: 41
Joined: Sat Aug 11, 2012 7:10 pm

Re: 2d lines using GLES2?

Fri Aug 07, 2015 3:54 pm

When I get home I'll see if I have any simple demo code that draws lines.
That would great, thanks.

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

Re: 2d lines using GLES2?

Sat Aug 08, 2015 7:08 pm

Sorry, I've been out of the house all day and I only just remembered about this thread. I'll have a look for you in the morning.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

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

Re: 2d lines using GLES2?

Sun Aug 09, 2015 9:32 am

http://www.peteronion.org.uk/OpenGLES/Ex1.tgz

You'll need cmake installed (sudo apt-get install cmake)

tar xvfz Ex1.tgz
cd Ex1
cmake .
make
./Ex1

The actual line drawing code is in Ex1.c, with all the generic openGL code in C-openGLES.c

Any problems let me know. It's not particularly well commented I'm affraid. One day I will get round to fininshing the set of demos I started to write 2 years ago :shock:

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

jonshouse
Posts: 41
Joined: Sat Aug 11, 2012 7:10 pm

Re: 2d lines using GLES2?

Fri Aug 14, 2015 8:03 pm

Great demo, thanks, some wizzy 3d stuff going on with those cubes :-) I will examine into cmake, my code is compiling currently with absolute paths and a long line of gcc -I -Ls, you way looks cleaner.

I managed to make the code I was hacking up work in the end. Seems the issue is that GL on the RPI does not want to work with integer values ?

For example, if I define an array of vertexes like this:

Code: Select all

GLfloat vertices[GLELEMENTS];
Then plot lines like this:

Code: Select all

glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_LINES,0,glvertexcount);
Then all is good and it works.

Change the code to work with ints like this :

Code: Select all

GLint vertices[GLELEMENTS];
and plot with:

Code: Select all

glVertexPointer(2, GL_INT, 0, vertices);
glDrawArrays(GL_LINES,0,glvertexcount);
Then all I get is a blank screen regardless of what values I place in the integer array, I tried for 6 hours to make it work with Ints, tried everything I could think off ! Any ideas ? :-)

Thanks,
Jon

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

Re: 2d lines using GLES2?

Fri Aug 14, 2015 8:33 pm

Have you looked to see if any errors are generated ?

And it looks like you are using GLES 1.1 not GLES 2.0... glVertexPointer is part of 1.1 but not 2.0.

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

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

Re: 2d lines using GLES2?

Fri Aug 14, 2015 11:29 pm

jonshouse wrote:Change the code to work with ints like this :

Code: Select all

GLint vertices[GLELEMENTS];
and plot with:

Code: Select all

glVertexPointer(2, GL_INT, 0, vertices);
glDrawArrays(GL_LINES,0,glvertexcount);
Then all I get is a blank screen regardless of what values I place in the integer array, I tried for 6 hours to make it work with Ints, tried everything I could think off ! Any ideas ? :-)

Thanks,
Jon
As PeterO said, glVertexPointer is GLES1.1 and if you're using that then GL_INT isn't even defined so the compiler should be complaining. You can use GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_FLOAT or GL_FIXED.
Under GLES2, glVertexAttribPointer goes one better and also allows GL_UNSIGNED_SHORT (and optionally GL_HALF_FLOAT_OES, but the RPi doesn't support that).

If you had checked glGetError() right after the glVertexPointer() you would have found it reporting GL_INVALID_ENUM.
She who travels light — forgot something.

jonshouse
Posts: 41
Joined: Sat Aug 11, 2012 7:10 pm

Re: 2d lines using GLES2?

Sat Aug 15, 2015 6:06 pm

Thanks everyone, good answers.
Somehow I have managed to mangle (thanks to clickable online docs and carelessness) 1.1 and 2, I also managed to pull headers in for both so it compiles (and works mostly). I need to unhack my code and pick either 1.1 or 2 and stick to it !

I am new to GL and made the mistake of learning it from "bits online" rather than a proper (on paper) book :-)

I will use the great Ex1 demo to compare with my code and unpick some of my mess to make it all GLES2.

Thanks,
Jon

tejonbiker
Posts: 30
Joined: Tue Aug 28, 2012 1:36 am

Re: 2d lines using GLES2?

Wed Aug 19, 2015 4:40 am

Hi, I working before with GLES 2.0 (a long time ago), but I build a very simple example in the pi, it's bundled with my libraries, but I think you can understand the workflow of an OGL ES 2.0 example.

To ge the code, run this:

Code: Select all

git clone https://github.com/tejonbiker/wire_engine.git
cd examples/hello_points/
make
./hello_points.bin
With this you will build the example and the execute.

I think the part of your interest resides in calculateSine() where I make the calculus of the points, the other thing to take into account is what type of line I am drawing, in display() you can find this function "glDrawArrays(GL_LINE_STRIP,0,N_POINTS);"

This is a line strip, the great thing about glDrawArrays is that takes every element specified before (in glVertexAttribPointer ) as a linked line.

I know this is hard, but is the most optimal way to make graphics in the pi.

I will here if you have any doubt.

jonshouse
Posts: 41
Joined: Sat Aug 11, 2012 7:10 pm

Re: 2d lines using GLES2?

Sat Aug 22, 2015 5:25 pm

think the part of your interest resides in calculateSine() where I make the calculus of the points, the other thing to take into account is what type of line I am drawing, in display() you can find this function "glDrawArrays(GL_LINE_STRIP,0,N_POINTS);"]
OK, thanks, I will look into that. I still have a lot to learn about GL.

I did get time to hack around with adding a crude GL driver on MAME. It still needs some work though.

http://www.jonshouse.co.uk/advmame.cgi

Thanks to everyone for the help and advice.

Return to “OpenGLES”

Who is online

Users browsing this forum: No registered users and 3 guests