GLBasic forum

Main forum => GLBasic - en => Topic started by: fivesprites on 2012-Jun-11

Title: Problem with shaders on Android
Post by: fivesprites on 2012-Jun-11
Hi,

Has anybody managed to get shaders working on the Android platform? 
No matter what I try, I can't seem to get even the most basic to work - even though they work without fault on PC.

Simple Fragment Shader (test.frag)

Code (glbasic) Select

void main(void)
{
  gl_FragColor = vec4( 1, 1, 0, 1);
}


Any request to load that shader using:

Code (glbasic) Select

IF (X_LOADSHADER(1, "", "test.frg"))
STDOUT "Shader loaded ok\n"
ELSE
STDOUT "FAILED TO LOAD SHADER!\n"
ENDIF


results in "FAILED TO LOAD SHADER" being lobbed out in the Android logs.  No other clues given :(

Any help would be greatly appreciated.

/Andy

Title: Re: Problem with shaders on Android
Post by: mentalthink on 2012-Jun-11
HI I think the trouble but I´m not sure it´s the version of OpenGL, GLbasic uses 1.0, and I suppose your device uses 2.0... OpenGL 1.0 to 2.0 changes in the mode how do the things internaly...

Not it´s too much problem beucase you can adapt the Krhonos Library OpenGL2.0 to GLbasic, I´m beggin comming soon to port...

Title: Re: Problem with shaders on Android
Post by: Slydog on 2012-Jun-11
Do fragment shaders work with GLBasic? (Since it's only OpenGL 1.1?)
I wonder if the hardware on the PC just didn't mind the shader code, while the Android version is more strict.

@mentalthink: Cool, never heard of the Khhonos Library yet!  So it MAY be possible to run OpenGL 2.0 in GLBasic?!?!
Title: Re: Problem with shaders on Android
Post by: fivesprites on 2012-Jun-11
Quote from: Ocean on 2012-Jun-11
"test.frg"  in the GLB code misses an 'a' `?

Unfortunately, no - that was a typo by we when writing the post - wish it was that simple!
Title: Re: Problem with shaders on Android
Post by: mentalthink on 2012-Jun-11
Quote@mentalthink: Cool, never heard of the Khhonos Library yet!  So it MAY be possible to run OpenGL 2.0 in GLBasic?!?!

Hi Slydog, I think not have to be too much complicated, I  port part of OpenGl 1.1 of Khronos too, and I think have to be very similar... the only trouble it´s testing in PC, but I think using the last Emulator of android , it´s capable of Open GLES 2.0 can be easy...

IF you interested in take a look at this, look this book, it´s awesoming the 3d whit OpenGl 2.0 can do...

http://opengles-book.com/downloads.html

take a look in wiki- installations, the books teaches how install an Emulator and a SDK?¿, about OPENGL ES 2.0, and look running in PC it´s absolutetly fantastic...

PS: If you take a look at krhonos have got a lot of libraries... like OPENAL... (I´m not sure if GLBsic uses this for audio, or it´s whit SDL)   :-[
Title: Re: Problem with shaders on Android
Post by: fivesprites on 2012-Jun-11
Quote from: Slydog on 2012-Jun-11
Do fragment shaders work with GLBasic? (Since it's only OpenGL 1.1?)
I wonder if the hardware on the PC just didn't mind the shader code, while the Android version is more strict.

@mentalthink: Cool, never heard of the Khhonos Library yet!  So it MAY be possible to run OpenGL 2.0 in GLBasic?!?!

It does look like it's an 2.0 thing.  It's a shame really as the shaders I'm using look lovely on the PC (using GLB) :(

Hopefully Gernot will be able to introduce support for it in the future.

Thanks guys.

/Andy
Title: Re: Problem with shaders on Android
Post by: Slydog on 2012-Jun-11
@fivesprites
QuoteIt's a shame really as the shaders I'm using look lovely on the PC (using GLB) :(

Hmm, so 2.0 shaders work on the PC using GLBasic? 
I thought OpenGL 1.1 was the standard on all platforms?
Or does the PC code just work somehow?!  Weird.

@mentalthink: There's a small chance I own that book already.  I bought a bunch at first to start iPhone programming, but barely cracked any of the covers!   :-[  But still too involved for me to dig into, I'll just program to use whatever features / version GLBasic exposes to me.
Title: Re: Problem with shaders on Android
Post by: fivesprites on 2012-Jun-11
Yep - works great!

Here's an example:  https://dl.dropbox.com/u/32204670/ShaderTest.zip (https://dl.dropbox.com/u/32204670/ShaderTest.zip)

This modifies the background image by changing the colour using RGB->HSV->RGB.  Move the mouse around to change the Hue and Saturation and the Left/Right mouse buttons to adjust the Value.

:)

Title: Re: Problem with shaders on Android
Post by: kanonet on 2012-Jun-12
Quote from: Slydog on 2012-Jun-11Hmm, so 2.0 shaders work on the PC using GLBasic? 
I thought OpenGL 1.1 was the standard on all platforms?
Or does the PC code just work somehow?!  Weird.
OpenGL <> OpenGL ES
As far as i know on all mobile devices GLB uses just OpenGL ES 1.1. But on desktop it uses OpenGL, i think in higher versions, but i dont know in detail.
Title: Re: Problem with shaders on Android
Post by: theprotocol on 2012-Jun-12
Aw, that's a bit disappointing. I assumed shader support for mobile platforms was in. Kinda puts a wrench in some of my ideas. ;(
Title: Re: Problem with shaders on Android
Post by: fuzzy70 on 2012-Jun-12
As far as I'm aware GLB defaults to the lower versions of GL /GLES for the sake of compatibility for as many target's as possible.

While my desktop can handle OpenGL 4.2 with ease while my laptop tops out on 2.1 I think.

Android is another minefield with regards to specs like gpu's (of which not all have).

Would the PLATFORMINFO$(GLEXT :xxxx)  be of any use or is that PC only?

Or maybe adding what you need along the lines of the gl.gbas include file might help. Am sure I have seen post's on the forum along those sort of lines.

Lee
Sent from my GT-I5700 using Tapatalk 2
Title: Re: Problem with shaders on Android
Post by: theprotocol on 2012-Jun-13
"Thinking out loud" post - will contain a lot of errors!

I've been looking into some makeshift way of overriding GLBasic's EAGLContext initialization when it generates mobile device code.

Thinking out loud, these are my initial assumptions:

- The existence of X_SETSHADER means that GLBasic is using the OpenGL 2.0 spec when available. Therefore, 2.0 functions are implemented somewhere in GLBasic. I'm assuming they are mostly interchangeable with OpenGL ES 2.0 calls.

- When GLBasic builds a mobile app (Android or iOS), the generated code creates a v1.1 GL Context. I'm looking for a way to switch this into a 2.0 context (Looking at this (http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/WorkingwithOpenGLESContexts/WorkingwithOpenGLESContexts.html) currently for iOS).

- Possible roadblock: even if we somehow manage to override the GLContext code that GLBasic generates with inline C/C++, does GLBasic arbitrarily block shader-related code from being built into mobile projects? It looks like the answer is probably no since shader functions return a "fail." I'm hoping this "false" response isn't hard coded by GLBasic, but rather comes from the OpenGL implementation (which returns false if you attempt shaders in a 1.1 context). If GLBasic is simply blocking 2.0 functions on mobile devices in a pre-determined way, then this is hopeless.

English version: Is the error "FAILED TO LOAD SHADER" coming from GLBasic, or OpenGL? I hope GLBasic leaves it to the OpenGL implementation (not hard coded in GLBasic generated mobile code).


Does anyone see any potential here?


edit: My approach here is iOS-centric. Android might be easier! It seems the Android API provides functions for switching the context version. For example:

Code (glbasic) Select
MGLsurfaceview.SetEGLContextclienntVersion(2)


Would be good if someone more knowledgeable on Android could chime in.
Title: Re: Problem with shaders on Android
Post by: Kitty Hello on 2012-Jun-13
GLBasic uses OpenGL|ES 1.1 since some devices don't support 2.0.
So, there's no shader support for mobile devices.
Title: Re: Problem with shaders on Android
Post by: fivesprites on 2012-Jun-13
Pretty much figured the same :(

Gernot, do you plan to introduce support for GLES2.0 at some point in the near future?  Is there anything we could do to help move this along?

Title: Re: Problem with shaders on Android
Post by: mentalthink on 2012-Jun-13
@fivesprites... I don´t try yet to make a port to opengl 2.0, but if I´m not wrong not it´s too much complex... How i told more above... I port part of the 1.0 whit more things... you can have very nive graphics whit 1.0, but was very easy make the mini-port , about the 2.0 I have plans to do it, becuase I stay very interested in this Library...

You can found in the forum, the way to make a wrap of Open GL, it´s the same manner I do the port of OpenGl-es 1.0, but you can read a bit about how make the things... Krhonos Group have a huge information, and if you search something like OPENGL es tutorial you will find some in english very very interesting...

Don´t care about 2.0 I´m sure in sometime perhaps it´s implemented, but How I told you make our self, not it´s too much complex...

PS: (I´m not proffesional programmer, and I can do it, and it´s very very fun!!!, a part of learn very interesting things.)
Title: Re: Problem with shaders on Android
Post by: theprotocol on 2012-Jun-14
Quote from: Kitty Hello on 2012-Jun-13
GLBasic uses OpenGL|ES 1.1 since some devices don't support 2.0.
So, there's no shader support for mobile devices.

Isn't it just a matter of creating a 2.0 GL context instead of 1.1 in the initialization? GLBasic already has this implemented for non-mobile platforms. Isn't it a trivial change to just optionally include this code path for mobile platforms? Like, some kind of initialization command to tell GLBasic to generate a 2.0 context when building mobile code.
Title: Re: Problem with shaders on Android
Post by: kanonet on 2012-Jun-14
the protocol again: OpenGL|ES <> OpenGL
This are to different libraries and you can not run OpenGl on mobile devices.
Title: Re: Problem with shaders on Android
Post by: theprotocol on 2012-Jun-14
Quote from: kanonet on 2012-Jun-14
the protocol again: OpenGL|ES <> OpenGL
This are to different libraries and you can not run OpenGl on mobile devices.


I know the difference between OpenGL and OpenGL ES. However, their implementations are VERY similar. The vast majority of commands are interchangeable. I sincerely doubt GLBasic on desktops using the programmable pipeline (2.0+) uses any code that doesn't exist in ES 2.0.

Most of the groundwork is done in the non-mobile codepath. To "port" it to OpenGL ES should be almost trivial. Almost the same commands and API (a few restrictions on shader variables come to mind).


In fact, the X_SETSHADER command can be run on mobiles - it just returns an error. If this error isn't some hardcoded thing that GLBasic has ("block all 2.0 commands if mobile") then it's coming from OpenGL ES, which is saying "Sorry, you're using 1.1, this command fails."

So, the first step is to switch to a 2.0 context in OpenGL ES. This is 1 line of code that needs to be changed. The rest shouldn't be too hard (fixed function commands wouldn't work anymore, but who cares - you want to program your pipeline anyway or else stick to 1.1).


edit: Summary version in case you still don't understand my point: OpenGL and OpenGL ES are extremely similar. Maybe 90% similar. If we simply establish a 2.0 GL Context then if we're lucky, GLBasic's OpenGL code should be THE SAME as required for OpenGL ES 2.0. If not, then we need some very minor tweaks (and obviously disable all fixed function commands and use the programmable pipeline commands only).
Title: Re: Problem with shaders on Android
Post by: Kitty Hello on 2012-Jun-14
wrong. ES 2.0 is totally different. There's no fixed function pipeline anymore. You have to program everything using shaders. (no glRotate, no glMultMatrix, no glEnable(GL_TEXTURE2D) )
It might be worth to do this at one point, but currently I'm having a lot more urgent things to push forward.
Title: Re: Problem with shaders on Android
Post by: theprotocol on 2012-Jun-14
Quote from: Kitty Hello on 2012-Jun-14
wrong. ES 2.0 is totally different. There's no fixed function pipeline anymore. You have to program everything using shaders. (no glRotate, no glMultMatrix, no glEnable(GL_TEXTURE2D) )
It might be worth to do this at one point, but currently I'm having a lot more urgent things to push forward.

The bolded part is exactly consistent with what I said. My point is GLBasic already has the shader codepath, and that part 99% the same in ES as it is in regular OpenGL (some changes within the shaders themselves though). I acknowledged many times already that you do indeed remove the entire fixed function pipeline. But the idea is there isn't really much "porting" to be done, pretty much copypaste the existing shader codepath and don't include fixed function stuff.

However, I'm not pressuring you or anything! I understand that you have priorities. But I'm saying there could be potential for a community driven effort to do this (I'm looking into it!) somehow.
Title: Re: Problem with shaders on Android
Post by: bigsofty on 2012-Jun-15
The biggest problem is the name, OpenGL 2.0, implies that this version is backwards compatible. The main thing they did with 2.0 is cut things out, no glbegin/end, no matrice stuff at all, some state changes are completely missing, etc... This means its not just a matter of changing some of your GL 1.1 engine, it's a complete re-write for 50%.

BTW Gernot, I don't know if you've seen this project, maybe it could help a move to 2.0 in the future... http://code.google.com/p/gles2-bc/

I would love shaders personally as I have to emulate them currently for shader like FX and I really could speed up my rendering with them too but i do realise it's a large project on its own right, Esp. for one developer and the large amount of platforms that GLB covers.
Title: Re: Problem with shaders on Android
Post by: mentalthink on 2012-Jun-15
@Bigsofty, thanks for the links, it´s very interesting...
Title: Re: Problem with shaders on Android
Post by: Kitty Hello on 2012-Jun-18
Quote
Known limitations¶
•currently supports only iPhone platform
◦porting to some other platforms should be easy
•fixed-point versions of the OpenGL ES 1.x API functions are not supported
•glColor4* is not supported

That's pretty much the stuff I was talking about.
Title: Re: Problem with shaders on Android
Post by: kanonet on 2012-Jun-18
Yeah and no news since almost 3 Years, looks pretty death.