GLSL Shader issue

Previous topic - Next topic

DaveG

Hi all,

I've recently been fiddling about with GLBasic and shaders and I think I'm missing something very very obvious as I'm not getting too far. I'm trying to apply a shader to a 2D texture and not much is happening (understandably on my Netbook as it doesn't support OpenGL 2, but my desktop and work laptop support 3 & 4). Here's my GLB code :


Code (glbasic) Select
LOCAL bFinished=FALSE

IF X_LOADSHADER (1, "", "plasma.frag") = FALSE
DEBUG "Unable to load shader.\n"
END
ENDIF

LOADSPRITE "ForestTexture.png", 1

X_OBJSTART 1
X_OBJADDVERTEX -iSquareSize,-iSquareSize, 0, 0, 1, 1 // Top left
X_OBJADDVERTEX iSquareSize,-iSquareSize, 0, 1, 1, 1 // Top right
X_OBJADDVERTEX iSquareSize,iSquareSize, 0, 1, 0, 1 // Bottom right
X_OBJADDVERTEX -iSquareSize,iSquareSize, 0, 0, 0, 1 // Bottom left
X_OBJADDVERTEX -iSquareSize,-iSquareSize, 0, 0, 1, 1 // Top left again
X_OBJEND

WHILE NOT bFinished = TRUE
X_MAKE3D -0.5, 0.5, 45
X_CAMERA 0,0,-0.5,0,0,0

X_SETTEXTURE 1, -1

X_AMBIENT_LT 0, RGB(255,255,255)

X_SETSHADER 1

X_DRAWOBJ 1,0

X_SETSHADER -1

SHOWSCREEN

bFinished = KEY (1)

WEND

X_MAKE2D

SLEEP 500


bFinished = FALSE

WHILE NOT bFinished = TRUE

X_SETSHADER 1

DRAWSPRITE 1,0,0

X_SETSHADER -1

// X_DRAWAXES 0,0,0

SHOWSCREEN

bFinished = KEY (1)

WEND

MOUSEWAIT


And here's the GLSL fragment shader :

Code (glbasic) Select
void main()
{
vec4 f4TheColourPurple;

TheColourPurple = vec4(0.5, 0.0, 0.5, 1.0);
// Setting Each Pixel To Purple.
gl_FragColor = TheColourPurple;
}


From what I can tell this should turn the output purple, but nothing much seems to be happening.

Has anyone got any ideas what I'm doing wrong?

Many thanks,
Dave.

DaveG

Apart from the variable name being wrong in the shader code which I've just noticed after I've posted it :)

Now it GPF's for some reason ...

Cheers,
Dave.

DaveG

Thanks.

Looks like the crash was unrelated to the code. I tried some other code and various GLB samples and examples and they crashed too.

I uninstalled GLB and reinstalled and the code ran without problems (apart from, as I say, not doing much).

Then I ran the web update and upgraded to the latest release (9.0.21) and the crash returned so it looks like there may have been some sort of regression introduced.

My machine is running Windows 7 (x64) and my video card is a Radeon 4850 with the drivers 8.812.0.0 dated the 4th of January 2011.

Let me know if there is anything else I can send to help fix this.

Cheers,
Dave.

MrTAToad

9.021 does seem to crash for everyone...

DaveG

Yep - just replicated it on Windows 7 x86 with an nVidia card. Works on 9.0.03, crashes after updating to 9.0.21.

Cheers,
Dave.

DaveG

Found the problem. GLB looks for your shaders in the Media directory rather than in your source directory, which makes sense. Not sure why X_LOADSHADER didn't return FALSE though.

Cheers,
Dave.

MrTAToad

No load commands do - you need to check for the presence of a file yourself.

DaveG

May not be a bad idea to clarify the docs then :

This command loads a GLSL (OpenGL Shading Language) shader into index index#.
If the shader loaded successfully, ok# will be TRUE.

I'm assuming that loaded in this context means compiled but it's not really clear. I only spotted it 'cos I ran it on Linux and there was a message about an fopen failing.

Cheers,
Dave.