Author Topic: CGE Sourcecode  (Read 6017 times)

Mopz

  • Guest
CGE Sourcecode
« on: May 28, 2013, 04:00:32 PM »
In the next NaaLaa release, CGE (Crappy Graphics Engine, used for 3D software rendering) will be completely removed. So I thought it could aswell make the source code public. I wrote all of this many, many years ago, but some of you might still find it interesting. The source code (C and ASM) come with some few, compiled, examples programs. But it's pretty much a light software version of OpenGL supporting triangle and vertex shaders.

Here's the package: http://www.naalaa.com/temp/cge.zip
« Last Edit: May 28, 2013, 04:06:07 PM by Mopz »

DJLinux

  • Guest
Re: CGE Sourcecode
« Reply #1 on: May 28, 2013, 07:54:58 PM »
Really good  job.
I wrote this kind of scanline raster assembler stuff (perspective corect) end of the 80th.
Now it's history or 'retro' style :-)

If you remove it from NaaLaa standard features it should be aviable as extension for >=V5.1
Of course it has its own charm.

DJ 

DJLinux

  • Guest
Re: CGE Sourcecode
« Reply #2 on: May 28, 2013, 08:23:50 PM »
I wonder me that your BMP loader in NaaLaa returns the right height of the image.
CGE used this *height = Get32Bits(fptr);
Normaly or often BMP's are bootom up images and the height is a negative number like -480 for a height of 480 pixels.

By the way I study the cgm format, (found it before from your NaaLaa mesh loader code)
what is it for a tool do you used in the past to create this 3D models ?

DJ

Mopz

  • Guest
Re: CGE Sourcecode
« Reply #3 on: May 29, 2013, 04:32:50 PM »
While studying I made a more advanced software renderer that had perspective correct texture- and bumpmapping. It also implemented phong shading and some other weird shaders invented by my mentor (dr. Anders Hast - he's got some good papers published in computer graphics programming). But it was dreadfully slow. So after my studies I wrote CGE (Crappy Graphics Engine) that I could actually write some games with. It's not perspective correct, instead I subdivide the triangles until a certain (really stupid) criteria of perspective correctness is met. The result looks much like that of the first Playstation console. This small game was one of the first things I wrote in naalaa:

http://www.youtube.com/watch?v=KihhpDwY9-U

Regarding the BMP-format, the upsidedown thing works in CGE because its coordinate system is also upside down ;)

The CGM (Crappy Graphics Model) format is my own. It's basically a version of the Geomview OFF format that can contain bitmap data for textures. The only program that outputs such models is GLOM ... that I wrote while taking a class in "advanced" computer graphics:



But CGE can also load normal OFF files.

I figure you've got an interesting background in programming? I'd love to hear your story :) Were you an Amiga, PC or Atari follower to start with?
« Last Edit: May 30, 2013, 04:04:05 PM by Mopz »

Aurel

  • Guest
Re: CGE Sourcecode
« Reply #4 on: May 30, 2013, 03:28:32 PM »
Yes joshy is a big expert for graphics stuff ,from GFABasic,GL4,freeBasic ..etc..etc

Aurel

  • Guest
Re: CGE Sourcecode
« Reply #5 on: May 30, 2013, 03:34:03 PM »
Marcus ...
I am wonderning when i see source code you only have few include files
Do you using GDI plus windows api for this rendering or something else...
because this examples work really smooth  ;)

Mopz

  • Guest
Re: CGE Sourcecode
« Reply #6 on: May 30, 2013, 04:01:33 PM »
Marcus ...
I am wonderning when i see source code you only have few include files
Do you using GDI plus windows api for this rendering or something else...
because this examples work really smooth  ;)

Yes, if you look at gdipp.h and gdipp.c (GDI Pixel Pusher) they include all windows api related stuff. As in naalaa I have a back buffer of the same size as the window that I push to the window with StretchDIBits.

Quote
Yes joshy is a big expert for graphics stuff ,from GFABasic,GL4,freeBasic ..etc..etc

Oh, didn't know that  :-[

Aurel

  • Guest
Re: CGE Sourcecode
« Reply #7 on: May 31, 2013, 09:52:45 AM »
Quote
I have a back buffer of the same size as the window that I push to the window with StretchDIBits.

aha i see, i am not sure where is this include ???
so you say that you have backbuffer where you draw graphics then what you use to flip
this buffer to window?
Do you use DC for this?
why i asking...i trying to find a way to create double buffered window with permanent
image on window without using WM_PAINT event...

Aurel

  • Guest
Re: CGE Sourcecode
« Reply #8 on: May 31, 2013, 10:05:21 AM »
Hi Marcus ..
I look again into source of gdipp and i must say that you do excellent job... ;)
I see that you use your rendering also under WM_PAINT...

I just thinking ...maybe will be good create cge as .dll so then can be used with any
other programming language,right?

Just one thing...
So all graphics in CGE are created with windows api only ...right?

Mopz

  • Guest
Re: CGE Sourcecode
« Reply #9 on: May 31, 2013, 04:21:07 PM »
I looked at TinyPTC when I wrote gdipp. I was (and am still) terrible at windows programming, but atleast I managed to add some functionality for input.

Yes, win api is all that is used to display the backbuffer. On Linux I've tried using opengl and glDrawPixels, but that one is dead slow, even when it comes to just drawing ONE image 60 times per second, which is what naalaa requires.
« Last Edit: May 31, 2013, 04:22:51 PM by Mopz »

DJLinux

  • Guest
Re: CGE Sourcecode
« Reply #10 on: June 03, 2013, 05:51:45 AM »
On Linux I've tried using opengl and glDrawPixels, but that one is dead slow, even when it comes to just drawing ONE image 60 times per second, which is what naalaa requires.
You have to use the XLIB from X server for this job.
The primary problem are if you use an RGBA or RGB buffer in NaaLaa and the users X11 windowmanager are currently in 15 or 16 bit you have to write your own image converter/blitter.

DJ