KGLX - Rendering Issues

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

KGLX - Rendering Issues

Post by PH3NOM »

So, I have just recently started programming with OpenGL.

Using KGLX on DC, so far the results are good

Models are in the format MD2

Texture filter is set to PVR_FILTER_BLINEAR, the only thing that could help is Mip-Mapping

Image

I have managed to work out a basic camera implementation

Image

So far so good

Image

But problems occur with clipping of large polygons

Image

Also obviously transparency not working correctly

Image

So I post here for help with Clipping and Transparency. Any comments appreciated.
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: KGLX - Rendering Issues

Post by BlueCrab »

I've never used KGLX, but from a hardware standpoint I might be able to at least partially explain things. Just prefacing it with that I've never used KGLX, so I don't know for sure if these are the issues you're running into or not...

With the original KGL that is included with KOS in kos-ports, you have to actually switch primitive lists, just like you would using the PVR directly. That means that you have to actually tell it that you're going to start rendering translucent polygons before you do so. With the original KGL, this is done by calling glKosFinishList() until it would open up the translucent list (if you're using the normal PVR init and not doing anything fancy, just once would do the trick after you're done with everything that's opaque). I don't know for sure if this is the same in KGLX, but it might explain the problems with transparency that you're seeing.

As for the clipping issue you're seeing, I can't think of anything off the top of my head that would cause that particular issue. If I had to guess, I'd say its probably that the polygon is getting culled, so check how you're handling culling and what KGLX does by default with that.
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

Re: KGLX - Rendering Issues

Post by PH3NOM »

BlueCrab wrote:With the original KGL that is included with KOS in kos-ports, you have to actually switch primitive lists, just like you would using the PVR directly.
Thanks BlueCrab!

I didnt realize that the list must be switched manually. That helped me solve the problem.

After that was fixed, I realized there was also something else going on.
The texture still looked pretty much like the previous post.

This problem was because I created the texture using GL_DECAL:

Code: Select all

glTexEnvi( GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_DECAL );
Switch to the mode GL_MODULATE and now success!

Furthermore, the blending mode must be set to achieve the desired transparency level:

Code: Select all

glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA ); /* Fully Transparent */
Image

Code: Select all

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); /* Semi Transparent */
Image
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

Re: KGLX - Rendering Issues

Post by PH3NOM »

Having fun with transparent textures

Image

And abusing the mess out of the SH4 ( ~20fps )

Image

Wrote a basic skybox render function

Image

But still having problems with clipping

Image

Nobody has any ideas here? If needed, I can post some relevant code...
patbier
DC Developer
DC Developer
Posts: 152
Joined: Fri Aug 29, 2003 1:25 am
Has thanked: 0
Been thanked: 0

Re: KGLX - Rendering Issues

Post by patbier »

Hello Phenom !

Is it possible to look at the source code ? It would be easier to find your clipping problem.
ImageAlice Dreams Tournament Dreamcast fans : http://www.facebook.com/alicedreamst
In August 2015, we had to change "Dynamite Dreams" name to "Alice Dreams Tournament"
dreamcast-news
DCEmu Freak
DCEmu Freak
Posts: 54
Joined: Tue Aug 30, 2011 3:29 am
Has thanked: 0
Been thanked: 0

Re: KGLX - Rendering Issues

Post by dreamcast-news »

I hope you'll fix the pb.
Good luck.
User avatar
Neoblast
DC Developer
DC Developer
Posts: 314
Joined: Sat Dec 01, 2007 8:51 am
Has thanked: 3 times
Been thanked: 1 time

Re: KGLX - Rendering Issues

Post by Neoblast »

Wow that's very nice. So you're working on the next "Hypertension" ?
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

Re: KGLX - Rendering Issues

Post by PH3NOM »

patbier wrote:Hello Phenom !

Is it possible to look at the source code ? It would be easier to find your clipping problem.
Check your inbox. I sent you a link to my source via PM.
Neoblast wrote:Wow that's very nice. So you're working on the next "Hypertension" ?
Nope. I am developing independently. :P
As things turn out, that project only needed modelers.

Anyway, here are some latest screens of what Im working on...
Image

Image

For the curious, here is a cdi to check out the demo
dc-engine-3d-cdi-070812.rar
(2.93 MiB) Downloaded 137 times
Because Patbier said his K:OS did not come with KGLX, I will post the library here:
libkglx.tar.gz
(95.87 KiB) Downloaded 131 times
User avatar
RyoDC
Mental DCEmu
Mental DCEmu
Posts: 366
Joined: Wed Mar 30, 2011 12:13 pm
Has thanked: 2 times
Been thanked: 0

Re: KGLX - Rendering Issues

Post by RyoDC »

Can I look at the source code too?
How do I try to build a Dreamcast toolchain:
Image
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

Re: KGLX - Rendering Issues

Post by PH3NOM »

RyoDC wrote:Can I look at the source code too?
Do you think you can help solve the clipping problem?
Because Im not ready to release the source, publicly...
Patbier and myself have worked together in the past, and he has trusted me with some of his sources.

But, if you have any questions about it, I would be happy to answer, and even share snippets of code / logic.
User avatar
Indiket
DC Developer
DC Developer
Posts: 99
Joined: Sun Sep 05, 2010 5:44 am
Has thanked: 0
Been thanked: 0

Re: KGLX - Rendering Issues

Post by Indiket »

Looking at the libkglx file you are using, I think you are using the same version as Heinrich Tillack (author of Iris3D), the 0.41, isn't it?

Did you try with Chui's implementation? I understand that it is more advanced and is compatible with OpenGl 1.2, but I don't know exactly how far did he arrive. I sent you a PM with the details, but maybe that clipping problem is already solved! :)
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

Re: KGLX - Rendering Issues

Post by PH3NOM »

Indiket wrote:Looking at the libkglx file you are using, I think you are using the same version as Heinrich Tillack (author of Iris3D), the 0.41, isn't it?

Did you try with Chui's implementation? I understand that it is more advanced and is compatible with OpenGl 1.2, but I don't know exactly how far did he arrive. I sent you a PM with the details, but maybe that clipping problem is already solved! :)
Well, I still have not looked at the"Chui" build.
But I did look at the /examples/ included in the kglx-0.4.1 package you sent me, as they were not included with kos.
I did realize that DC uses "slightly" different z-clipping than normal gl.

Code: Select all

glEnable(GL_KOS_NEARZ_CLIPPING);
Seems to help mostly.
The skybox is rendered fine, I just need to fix the rotations for the *new texture format being used for environment map.
Image

Image
User avatar
RyoDC
Mental DCEmu
Mental DCEmu
Posts: 366
Joined: Wed Mar 30, 2011 12:13 pm
Has thanked: 2 times
Been thanked: 0

Re: KGLX - Rendering Issues

Post by RyoDC »

...
Last edited by RyoDC on Wed Oct 17, 2012 7:39 am, edited 1 time in total.
How do I try to build a Dreamcast toolchain:
Image
User avatar
Neoblast
DC Developer
DC Developer
Posts: 314
Joined: Sat Dec 01, 2007 8:51 am
Has thanked: 3 times
Been thanked: 1 time

Re: KGLX - Rendering Issues

Post by Neoblast »

Do you get full 60 fps in these tests? Tried chui's version?
It's more advanced
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

Re: KGLX - Rendering Issues

Post by PH3NOM »

Neoblast wrote:Do you get full 60 fps in these tests? Tried chui's version?
It's more advanced
Yeah, Indiket sent me Chui's KGLX some time ago. In the end, it was not any faster and led to some transparency problems.

But yes, now things are rendered at Full 640x480p@60fps.

Thanks to some small optimizations advised by Bouz on the forums here, DC-Engine-3D is capable of Rendering ~50,000 polys/second

And there is still some room to optimize :P

Image
Attachments
dc-engine-3d-111012.rar
(1.99 MiB) Downloaded 104 times
TapamN
DC Developer
DC Developer
Posts: 104
Joined: Sun Oct 04, 2009 11:13 am
Has thanked: 2 times
Been thanked: 88 times

Re: KGLX - Rendering Issues

Post by TapamN »

That doesn't actually run at 60 FPS on real hardware. It's 30 FPS when looking up into the sky, and 20 FPS when looking at the grass.
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

Re: KGLX - Rendering Issues

Post by PH3NOM »

TapamN wrote:That doesn't actually run at 60 FPS on real hardware. It's 30 FPS when looking up into the sky, and 20 FPS when looking at the grass.
Thank you for testing. Right now my DC is broken and i can not test.

I have re-written the render code, now based on meshes optimized for use with glVertexPointer().

Code: Select all

void DCE_GlRenderArray( DCE_MESH * mesh )
{    
    glBindTexture(GL_TEXTURE_2D, mesh->texaddr);
    
    glVertexPointer(3, GL_FLOAT, 0, mesh->vert);    
    glEnableClientState(GL_VERTEX_ARRAY); 
    
    glTexCoordPointer(2, GL_FLOAT, 0, mesh->texcoord);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);    
    
    if(mesh->primitive==DCE_RENDER_QUAD)
       glDrawArrays(GL_QUADS, 0, mesh->verts*mesh->primitive );
    else
       glDrawArrays(GL_TRIANGLES, 0, mesh->verts*mesh->primitive );
    
    glDisableClientState(GL_VERTEX_ARRAY);   
}
With that, I have written a utility to export 3ds models into my optimized DCE_MESH format.

Can someone test on real hardware?

Image

Image
Attachments
dc-engine-3d-111212.rar
(2.55 MiB) Downloaded 98 times
User avatar
RyoDC
Mental DCEmu
Mental DCEmu
Posts: 366
Joined: Wed Mar 30, 2011 12:13 pm
Has thanked: 2 times
Been thanked: 0

Re: KGLX - Rendering Issues

Post by RyoDC »

Phenom, tell me please, how do you debug your applications?
How do I try to build a Dreamcast toolchain:
Image
TapamN
DC Developer
DC Developer
Posts: 104
Joined: Sun Oct 04, 2009 11:13 am
Has thanked: 2 times
Been thanked: 88 times

Re: KGLX - Rendering Issues

Post by TapamN »

The newest one doesn't even seem to render. I can see the console output of the initialization and FPS counter, but get a black screen. It doesn't freeze completely, as the FPS counter still periodically updates. I couldn't get the controller or keyboard to do anything, like quit the program, either.
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

Re: KGLX - Rendering Issues

Post by PH3NOM »

TapamN wrote:The newest one doesn't even seem to render. I can see the console output of the initialization and FPS counter, but get a black screen. It doesn't freeze completely, as the FPS counter still periodically updates. I couldn't get the controller or keyboard to do anything, like quit the program, either.
Well when it first loads, the mesh will be behind you so just use the d-pad to turn around.
RyoDC wrote:Phenom, tell me please, how do you debug your applications?
Well, I dont use a debugger, really.

When things dont work as I suspect they should, I start throwing some printf() statements to track the progress.

Most DC devs probably frown on me for doing so much testing using an emulator, lol.

If you have more specific questions, feel free to shoot me a PM.
Post Reply