Author Topic: Problem with shaders on Android  (Read 7279 times)

Offline fivesprites

  • Mr. Polyvector
  • ***
  • Posts: 101
    • View Profile
    • FiveSprites
Problem with shaders on Android
« 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


Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3372
  • Integrated Brain
    • View Profile
Re: Problem with shaders on Android
« Reply #1 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...


Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 932
  • KodeSource
    • View Profile
    • KodeSource
Re: Problem with shaders on Android
« Reply #2 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?!?!
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Offline fivesprites

  • Mr. Polyvector
  • ***
  • Posts: 101
    • View Profile
    • FiveSprites
Re: Problem with shaders on Android
« Reply #3 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!

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3372
  • Integrated Brain
    • View Profile
Re: Problem with shaders on Android
« Reply #4 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)   :-[

Offline fivesprites

  • Mr. Polyvector
  • ***
  • Posts: 101
    • View Profile
    • FiveSprites
Re: Problem with shaders on Android
« Reply #5 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

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 932
  • KodeSource
    • View Profile
    • KodeSource
Re: Problem with shaders on Android
« Reply #6 on: 2012-Jun-11 »
@fivesprites
Quote
It'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.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Offline fivesprites

  • Mr. Polyvector
  • ***
  • Posts: 101
    • View Profile
    • FiveSprites
Re: Problem with shaders on Android
« Reply #7 on: 2012-Jun-11 »
Yep - works great!

Here's an example:  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.

:)


Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: Problem with shaders on Android
« Reply #8 on: 2012-Jun-12 »
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.
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.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline theprotocol

  • Mc. Print
  • *
  • Posts: 22
    • View Profile
Re: Problem with shaders on Android
« Reply #9 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. ;(

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
Re: Problem with shaders on Android
« Reply #10 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
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

Offline theprotocol

  • Mc. Print
  • *
  • Posts: 22
    • View Profile
Re: Problem with shaders on Android
« Reply #11 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 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.
« Last Edit: 2012-Jun-13 by theprotocol »

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10746
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Problem with shaders on Android
« Reply #12 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.

Offline fivesprites

  • Mr. Polyvector
  • ***
  • Posts: 101
    • View Profile
    • FiveSprites
Re: Problem with shaders on Android
« Reply #13 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?


Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3372
  • Integrated Brain
    • View Profile
Re: Problem with shaders on Android
« Reply #14 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.)