PDA

View Full Version : OpenGL 3.x cube problem



noeska
20-12-2009, 07:56 PM
System: Vista/WindowsXP
Compiler/IDE: Delphi2009
Libraries: OpenGL 3.x
Technique: Rendering Cube / Vector & Matrix Math / Conversion from cpp

Next in my opengl3.x adventures is trying to display a cube, but i must be doing something wrong.

The original is available from: http://nopper.tv/opengl_3_2.html (example03)

This is my attempt: http://www.noeska.net/downloads/Ogl3Cube1.zip .

Who can help me to find out what i do wrong. Also i found the original not to be logic as in the render part i do not see references as to what is rendered?

JSoftware
20-12-2009, 10:42 PM
Try altering the attach function to this:


procedure TGLSLProgram.Attach(ashader: TShader);
begin
inherited Attach(ashader);
ashader.Compile();
writeln(ashader.log);
glAttachObjectARB(FProgramObject, ashader.FShaderObject);
glDeleteObjectARB(ashader.FShaderObject);
end;


At least on my computer with a fairly new card I get "error C0201: unsupported version 150"

noeska
21-12-2009, 05:16 PM
On my pc with latest ati drivers i get the following from the log:
18:11:59 Vertex shader was successfully compiled to run on hardware.
18:11:59 Fragment shader was successfully compiled to run on hardware. WARNING: 0:3: warning(#239) Declaration should include a precision qualifier or the default precision should have been previously declared
18:11:59 Fragment shader(s) linked, vertex shader(s) linked. WARNING: 0:3: warning(#239) Declaration should include a precision qualifier or the default precision should have been previously declared

I also tried lowering the version in the shaders but no cube visible yet ... But then again the cpp original also shows a black screen on my pc...

noeska
21-12-2009, 06:45 PM
The results from:


// http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml
g_projectionLocation := glslsimpleprog.GetUniformLocation('projectionMatri x');

// http://www.opengl.org/sdk/docs/man/xhtml/glGetUniformLocation.xml
g_modelViewLocation := glslsimpleprog.GetUniformLocation('modelViewMatrix ');

// http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml
g_vertexLocation := glslsimpleprog.GetAttribLocation('vertex');

// http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml
g_normalLocation := glslsimpleprog.GetAttribLocation('normal');


are:
19:36:58 1
19:36:58 0
19:36:58 -1
19:36:58 -1

Now the -1 does not look correct ...

Luuk van Venrooij
21-12-2009, 09:57 PM
He Noeska,

Cool to see that you are getting into OpenGL 3.x. I have been working with it for a few months now. I spotted two errors in your program.

First check the glGetAttribLocation defenition in the dgl header. It takes a string while it should take a PGLChar. Then these lines will return good indices:

// http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml
g_vertexLocation := glslsimpleprog.GetAttribLocation('vertex');

// http://www.opengl.org/sdk/docs/man/xhtml/glGetAttribLocation.xml
g_normalLocation := glslsimpleprog.GetAttribLocation('normal');

Second look into vertex array objects. These are required to when using VBO`s in OGL 3.x. You seem to be using them in your first tutorial.
http://www.opengl.org/wiki/Vertex_Array_Objects

The examples you are using arent proper OGL 3.x. They might work on nvidia because they usually permit more errors but these demo`s wont work on ati.

Also I see you are using OGL 3.2. Make sure when using ATI you use the latest catalyst 9.12 drivers. These is the first version that supports 3.2 properly.

If you still have problems pm me. I can send you the code of my new framework that works on ati and nvidia correctly.

Regards,

Luuk

noeska
22-12-2009, 06:59 PM
I filed a bugreport on the dglopengl header using string instead of pglchar.
With a quick change on the local copy of it i now get correct answers 1 and 0.

With the c source not using vertex array object i asumed that to be optional, so tomorow i do a rewrite including them also.

But should not opengl 3.x work the same regardless of your videocard being ati or nvidia? I do not want seperate code paths.

Luuk van Venrooij
22-12-2009, 08:48 PM
If you stick to the base that should be the case but like i said before the code c code you use isnt correct OGL 3.x code:)

noeska
24-12-2009, 06:31 PM
On the opengl site they are presented as opengl 3.2 example code ;-)
So this is going to be more a challenge then i expected it to be.
Do you have some pointers to proper documentation / examples?

Also adding a vao does not help :-(

Here is my new sourcecode: http://www.noeska.net/downloads/Ogl3Cube2.zip

Luuk van Venrooij
25-12-2009, 03:01 PM
He noeska,

Here are some examples which I found verry usefull:

http://www.g-truc.net/post-0233.html

Also I`m currently working on my website and my OGL3.2 framework should be on svn somewhere next week.

Luuk

noeska
25-12-2009, 06:22 PM
Found some bugs in passing the arrays trough the calculations. Fixed that.
But still no cube :-(

Latest version:
http://www.noeska.net/downloads/Ogl3Cube3.zip

noeska
25-12-2009, 10:36 PM
Found the real problem :-)
In the resizewindow part i already 'publish' the projectionlocation matrix, but the location is not known yet and default being 0. But when requested its location becomes 1 resulting that it is overwritten by the modelview matrix that gets location 0. So as a workaround i calculate the matrix as before but only 'publish' it in the init part.
And next the cube showed up :-)

Final source: http://www.noeska.net/downloads/Ogl3Cube4.zip

noeska
28-12-2009, 09:35 AM
Finished some more examples from http://nopper.tv/opengl_3_2.html

Here are the examples in delphi: http://www.noeska.net/ogl3xexamples.zip

Bugs:
- i dont trust the cubemapping example, or it could be the tga reader flipping textures.
- the particle system does not work with the the shape textures due to in the fragment shader gl_PointCoord is always 0. But instead it shows red squares as points.

@Luuk van Venrooij: What is the url of your website, so i can have a look at your ogl3 progress.

noeska
29-12-2009, 11:15 PM
Today i was able to test the particle system on nvidia hardware and there it works.