Real Software Forums
http://forums.realsoftware.com/

Help with glShaderSourceARB (GLSL shaders)
http://forums.realsoftware.com/viewtopic.php?f=4&t=26399
Page 1 of 1

Author:  Fishy [ Mon Feb 09, 2009 9:31 pm ]
Post subject:  Help with glShaderSourceARB (GLSL shaders)

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!

Author:  jquan [ Tue Feb 10, 2009 1:06 am ]
Post subject:  Re: Help with glShaderSourceARB (GLSL shaders)

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.

Author:  Fishy [ Tue Feb 10, 2009 1:33 am ]
Post subject:  Re: Help with glShaderSourceARB (GLSL shaders)

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.

Author:  timhare [ Tue Feb 10, 2009 2:26 am ]
Post subject:  Re: Help with glShaderSourceARB (GLSL shaders)

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

Author:  Fishy [ Tue Feb 10, 2009 2:36 am ]
Post subject:  Re: Help with glShaderSourceARB (GLSL shaders)

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.

Author:  Fishy [ Tue Feb 10, 2009 2:57 am ]
Post subject:  Re: Help with glShaderSourceARB (GLSL shaders)

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.

Author:  timhare [ Tue Feb 10, 2009 11:05 am ]
Post subject:  Re: Help with glShaderSourceARB (GLSL shaders)

Make sure glB is always 1.

Author:  Fishy [ Tue Feb 10, 2009 11:32 pm ]
Post subject:  Re: Help with glShaderSourceARB (GLSL shaders)

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

Author:  timhare [ Wed Feb 11, 2009 12:43 am ]
Post subject:  Re: Help with glShaderSourceARB (GLSL shaders)

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

Author:  mitch_stgt [ Sat Feb 14, 2009 7:47 pm ]
Post subject:  Re: Help with glShaderSourceARB (GLSL shaders)

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

Author:  Fishy [ Tue Feb 17, 2009 1:57 pm ]
Post subject:  Re: Help with glShaderSourceARB (GLSL shaders)

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.

Author:  mitch_stgt [ Wed Feb 18, 2009 9:33 am ]
Post subject:  Re: Help with glShaderSourceARB (GLSL shaders)

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.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/