Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Dec 12, 2019 11:14 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Help with glShaderSourceARB (GLSL shaders)
PostPosted: Mon Feb 09, 2009 9:31 pm 
Offline

Joined: Fri Dec 16, 2005 10:19 pm
Posts: 493
I want to use GLSL shaders.

From http://nehe.gamedev.net/data/articles/article.asp?article=21 comes this code for using shaders:

Quote:
char * my_fragment_shader_source;
char * my_vertex_shader_source;

// Get Vertex And Fragment Shader Sources
my_fragment_shader_source = GetFragmentShaderSource();
my_vertex_shader_source = GetVertexShaderSource();

GLenum my_program;
GLenum my_vertex_shader;
GLenum my_fragment_shader;

// Create Shader And Program Objects
my_program = glCreateProgramObjectARB();
my_vertex_shader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
my_fragment_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);

// Load Shader Sources
glShaderSourceARB(my_vertex_shader, 1, &my_vertex_shader_source, NULL);
glShaderSourceARB(my_fragment_shader, 1, &my_fragment_shader_source, NULL);

// Compile The Shaders
glCompileShaderARB(my_vertex_shader);
glCompileShaderARB(my_fragment_shader);

// Attach The Shader Objects To The Program Object
glAttachObjectARB(my_program, my_vertex_shader);
glAttachObjectARB(my_program, my_fragment_shader);

// Link The Program Object
glLinkProgramARB(my_program);

// Use The Program Object Instead Of Fixed Function OpenGL
glUseProgramObjectARB(my_program);




My issue is with the glShaderSourceARB lines.

My GLextARB module has the method:

Sub glShaderSourceARB(glA As Integer, glB As Integer, glC As String, glD As Integer)
#pragma DisableBackgroundTasks
Declare Sub CallToGL Lib kOpenGLextARBLib Alias "glShaderSourceARB" (glA As Integer,glB As Integer,glC As PString,glD As Integer)
CallToGL glA,glB,glC,glD
End Sub


I want to use this method (or make a version of it I can use). No matter what I do, it unexpectedly quits on that line. The last parameter apparently is supposed to be a null pointer. I have tried having the last parameter be a ptr and setting it to null. I have tried shader source with unix and windows line ends. I have tried CString instead of PString and I have tried adding a nil to the end. I simply can't make it work.

How do I use glShaderSourceARB?

Thanks!

_________________
- Craig Macomber -
See my rb apps at:
http://www.spincraftsoftware.com/
Lead Programmer for Fragmented Galaxy, an MMORTS:
http://f-g.wikidot.com/


Top
 Profile  
Reply with quote  
 Post subject: Re: Help with glShaderSourceARB (GLSL shaders)
PostPosted: Tue Feb 10, 2009 1:06 am 
Offline

Joined: Mon Feb 05, 2007 11:35 am
Posts: 98
I'm still learning the fine art of declares myself, but have you tried setting that last gID parameter as Ptr instead, ie:

Declare Sub CallToGL Lib kOpenGLextARBLib Alias "glShaderSourceARB" (glA As Integer,glB As Integer,glC As PString,glD As Ptr)

You can then pass Nil for gID.

I'll also direct your attention to Charles Yeomans' excellent declares resource at
http://www.declaresub.com/ideclare/
Head to the "Declare Statements" chapter and go to the subsection on Memoryblocks for more on Null pointers.

_________________
Regards,

Jeff Quan
jeff@jcquan.com
http://www.jcquan.com/JQportfolio
My RBGL replacement classes: http://www.jcquan.com/REALbasic


Top
 Profile  
Reply with quote  
 Post subject: Re: Help with glShaderSourceARB (GLSL shaders)
PostPosted: Tue Feb 10, 2009 1:33 am 
Offline

Joined: Fri Dec 16, 2005 10:19 pm
Posts: 493
jquan wrote:
I'm still learning the fine art of declares myself, but have you tried setting that last gID parameter as Ptr instead, ie:

Declare Sub CallToGL Lib kOpenGLextARBLib Alias "glShaderSourceARB" (glA As Integer,glB As Integer,glC As PString,glD As Ptr)

You can then pass Nil for gID.

I'll also direct your attention to Charles Yeomans' excellent declares resource at
http://www.declaresub.com/ideclare/
Head to the "Declare Statements" chapter and go to the subsection on Memoryblocks for more on Null pointers.


That is one of the things I tried. I had a lot of hope for that one.

Well, I tried that (again) and messing with the string (PString seemed like the wrong thing, and WString (what ever that is) and CString did not work.) I don't know what a CFStringRef is, but when use CFStringRef and pass a null pointer, it does not crash. Maybe I can make it work. Thanks. If I get it all running I'll post code.

_________________
- Craig Macomber -
See my rb apps at:
http://www.spincraftsoftware.com/
Lead Programmer for Fragmented Galaxy, an MMORTS:
http://f-g.wikidot.com/


Top
 Profile  
Reply with quote  
 Post subject: Re: Help with glShaderSourceARB (GLSL shaders)
PostPosted: Tue Feb 10, 2009 2:26 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
That declare is puzzling. It doesn't match the documentation I have seen. I would write it as

(shaderObj as Integer, nShader as Integer, ByRef shaderSource as CString, ByRef shaderLength as Integer)

HTH,
Tim


Top
 Profile  
Reply with quote  
 Post subject: Re: Help with glShaderSourceARB (GLSL shaders)
PostPosted: Tue Feb 10, 2009 2:36 am 
Offline

Joined: Fri Dec 16, 2005 10:19 pm
Posts: 493
timhare wrote:
That declare is puzzling. It doesn't match the documentation I have seen. I would write it as

(shaderObj as Integer, nShader as Integer, ByRef shaderSource as CString, ByRef shaderLength as Integer)

HTH,
Tim


I saw somewhere that null termination is assumed if length is null, and the length was supposed to point to an array of lengths or something. I got really confused. I'll see if I can make it work your way. I may have it not crashing, but it it does not work, so maybe that will help.

Thanks.

_________________
- Craig Macomber -
See my rb apps at:
http://www.spincraftsoftware.com/
Lead Programmer for Fragmented Galaxy, an MMORTS:
http://f-g.wikidot.com/


Top
 Profile  
Reply with quote  
 Post subject: Re: Help with glShaderSourceARB (GLSL shaders)
PostPosted: Tue Feb 10, 2009 2:57 am 
Offline

Joined: Fri Dec 16, 2005 10:19 pm
Posts: 493
I got your version of the declare to not crash:
Sub X2glShaderSourceARB(glA As Integer, glB As Integer, glC As String)
#pragma DisableBackgroundTasks
Declare Sub CallToGL Lib kOpenGLextARBLib Alias "glShaderSourceARB" (shaderObj as Integer, nShader as Integer, ByRef shaderSource as CString, ByRef shaderLength as Integer)
dim m As New MemoryBlock(0)
dim b As new BinaryStream(m)
b.Write(glC+Chr(0))
dim s As CString=glc
dim l As Integer=Len(glC)
CallToGL (glA,glB,s,l)
End Sub


Same result though, the shader does not seem to run. I'll work on it more tomorrow.

Thanks.

_________________
- Craig Macomber -
See my rb apps at:
http://www.spincraftsoftware.com/
Lead Programmer for Fragmented Galaxy, an MMORTS:
http://f-g.wikidot.com/


Top
 Profile  
Reply with quote  
 Post subject: Re: Help with glShaderSourceARB (GLSL shaders)
PostPosted: Tue Feb 10, 2009 11:05 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Make sure glB is always 1.


Top
 Profile  
Reply with quote  
 Post subject: Re: Help with glShaderSourceARB (GLSL shaders)
PostPosted: Tue Feb 10, 2009 11:32 pm 
Offline

Joined: Fri Dec 16, 2005 10:19 pm
Posts: 493
It worked!

Thanks for all the declare tips. I think I know how to do declares now!

I got the two error checking declares working, and got error text and codes and everything. Turns out my fragment shader had the "void" capitalized!

Shaders are now working! Declares are somewhat understood, and OpenGl is making sense. Thanks!

I'll be happy to provide any of my other code, or the project if desired.

here is my error checking method (appends errors to a Log string array, and beeps on error codes).

Sub ErrorCheck(obj As Integer=-1)


#pragma DisableBackgroundTasks



Declare Sub CallToGL Lib kOpenGLextARBLib Alias "glGetInfoLogARB" (glA As Integer,glB As Integer,glC As ptr,glD As Ptr)

if Obj<>-1 then

dim m As New MemoryBlock(1000)
'dim b As new BinaryStream(m)
'b.Write(s+Chr(0))
dim m2 As new MemoryBlock(4)

CallToGL obj,1000,m2,m
dim ss As String=m.StringValue(0,m2.Int32Value(0))
if ss<>"" Then
log.Append(ss)
end if

'glGetInfoLogARB(GLhandleARB object, GLsizei maxLenght, GLsizei *length, GLcharARB *infoLog)

end if

dim er As Integer=glGetError()
if er <> 0 then
Beep
end
End Sub


Top
 Profile  
Reply with quote  
 Post subject: Re: Help with glShaderSourceARB (GLSL shaders)
PostPosted: Wed Feb 11, 2009 12:43 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
You can replace the memoryblock m2 with an integer passed byRef.

Declare ... glC As ptr, ...
dim m2 as new MemoryBlock(4)
CallToGl obj,1000,m2,m
dim outLength as integer = m2.Int32Value(0)

is equivalent to

Declare ... ByRef glC as Integer, ...
dim outLength as integer
CallToGl obj,1000,outLength,m

It can make your code easier to deal with.

HTH,
Tim


Top
 Profile  
Reply with quote  
 Post subject: Re: Help with glShaderSourceARB (GLSL shaders)
PostPosted: Sat Feb 14, 2009 7:47 pm 
Offline

Joined: Thu Oct 13, 2005 1:05 am
Posts: 101
Nice !
Can you share/ upload some demo source (zipped) of that if it is ready (complies / runs) ?

Would it be possible to use that for such shader programms like Raytracer on GPU....
http://www.clockworkcoders.com/oglsl/
Or does your Code means other usage of shader / needs more than only GLSL code (some libs not available in OS X for example)

Thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: Help with glShaderSourceARB (GLSL shaders)
PostPosted: Tue Feb 17, 2009 1:57 pm 
Offline

Joined: Fri Dec 16, 2005 10:19 pm
Posts: 493
mitch_stgt wrote:
Nice !
Can you share/ upload some demo source (zipped) of that if it is ready (complies / runs) ?

Would it be possible to use that for such shader programms like Raytracer on GPU....
http://www.clockworkcoders.com/oglsl/
Or does your Code means other usage of shader / needs more than only GLSL code (some libs not available in OS X for example)

Thanks

I managed to get GLSL code to run from realbasic. It is very crude and I haven't got it to work with textures yet so it is not really very interesting. I'll leave it up to you to figure what you can and can not do with GLSL.

Once I get it working and in a reasonable state, I'll upload it somewhere.

_________________
- Craig Macomber -
See my rb apps at:
http://www.spincraftsoftware.com/
Lead Programmer for Fragmented Galaxy, an MMORTS:
http://f-g.wikidot.com/


Top
 Profile  
Reply with quote  
 Post subject: Re: Help with glShaderSourceARB (GLSL shaders)
PostPosted: Wed Feb 18, 2009 9:33 am 
Offline

Joined: Thu Oct 13, 2005 1:05 am
Posts: 101
Thanks.

I dont want to do really normal grafic (texture) things.
I want to use GLSL for compute things on the GPU insted of CPU.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group