GDR Forum Index
Podcast Podcast
Dev Dev Logs
Search Search
RSS RSS
Register Register
Log in Log in
Reply to topic GDR Forum Index -> Game Developer's Refuge -> Development Log - Gliese: Gamedev Support Library Page 1, 2, 3  Next
View previous topic :: View next topic  
Author Message
NyanNyanKoneko
Contributor

Joined: 19 Oct 2005
Posts: 450
Location: In your L1 CPU cache
PostPosted: Sat Dec 01, 2007 6:50 pm    Post subject: Development Log - Gliese: Gamedev Support Library Reply with quote

So, I've been working on this game engine in my spare time. I think when it's finished, I might write some neat documentation and sell it. It's a game-making SDK written in C. It has a similar design to allegro or SDL. It will support 2d / 3d graphics, math, scripting, input, networking, and audio. The base libraries so far are SDL, SDL Image, glew, opengl, and glu. Audio will be implemented using libvorbis and OpenAL. The scripting language will be Lua. I'm not sure if I'll use standard sockets or SDL_Net for networking. I suspect the latter. It also might be a good idea for me to make a DirectX port, but I don't like the idea that the opengl shaders won't work with directx. I want it to be as easy as possible to port between Linux / Unix, Windows, and Mac OS.

I finished up most of the input and started to work on the graphics. I'm at the point, though, where I need to implement the mathematics engine to complete the graphics engine, so here's a screenshot of the latest build.



As you can see, I can load models (animated and static), texture them, apply multiple textures, apply lighting, and move them around. The models are in a proprietary format, but I'm thinking I'll find a way to load a more well-known format.

Up next though are 3D planes.


Edited by NyanNyanKoneko on Mon Dec 10, 2007 4:37 pm; edited 1 time
View user's profile Send private message Visit poster's website
sonrisu
Moderator

Joined: 31 Aug 2005
Posts: 4998
Location: Silicon Valley!
PostPosted: Sat Dec 01, 2007 7:55 pm    Post subject: Reply with quote

Why not create loaders to import all sorts of the major players? Maya, 3DS, QIII?

Sounds neat. Interesting that you're building it on top of SDL. Is the license "free" enough that you'd be able to sell what you create for money (I'm assuming yes).
View user's profile Send private message Visit poster's website
NyanNyanKoneko
Contributor

Joined: 19 Oct 2005
Posts: 450
Location: In your L1 CPU cache
PostPosted: Sat Dec 01, 2007 8:41 pm    Post subject: Reply with quote

Sonrisu, I'm SDL uses the LGPL license, which I believe allows for commercial applications.

Anyway, onto planes. There are two ways to define both lines and planes. Either by two / three points, or by a single point and a vector.



A line can be defined by the shortest path between point a and point b. A line can also be defined by a point and a vector. In games, it makes little difference although I prefer point-vector form since it's so easy to adjust the length of the line.

Similarly, a plane can be defined by 3 points or by a point with a normal. The problem with defining a plane as simply being 3 points is that it's difficult to tell what's in front and what's in back. With point-normal vector notation, we not only have a plane, we can clearly see which way is on top and which way is below the plane. Similarly, you can get the point-normal vector variables from 3 points. If you think of the three points of the plane as a triangle, and you compute the cross product with the vectors made up of P0->P1 and P0->P2, you'll get a vector which you can normalize which defines the outward direction counter-clockwise triangle face - the default in OpenGL.

Similarly, telling if points are on top of the plane is rather trivial. Create a new vector from the plane-point to the point we want to test. If the dot product of the plane normal and the new vector is below 0, then the point is behind the plane! Similarly, you can test each point of a bounding box to see if it's in front of a plane for easy culling.

--------------------------------------------

Sphere-Plane Detection.

The distance between the center of a sphere and the plane is the dot product of the plane normal and the center point of the sphere. If the sphere is in front of the plane, the distance is positive, otherwise it's negative.
View user's profile Send private message Visit poster's website
sonrisu
Moderator

Joined: 31 Aug 2005
Posts: 4998
Location: Silicon Valley!
PostPosted: Sun Dec 02, 2007 6:39 am    Post subject: Reply with quote

This stuff really is interesting. If anyone's taken a computer graphics class, or linear algebra, they'll know all about it. I wonder if it wouldn't be too much work to throw up some code, or either equations showing how it all works out -- or at least the computation and comparison of all the normal business.
View user's profile Send private message Visit poster's website
Bean
Admin

Joined: 20 Aug 2005
Posts: 3776

PostPosted: Sun Dec 02, 2007 7:35 am    Post subject: Reply with quote

One thing I can say after working on my engine for I donno how long now. It gets easier as you go. It's tough at first because there Is a lot of math functions and basic building blocks that you must bring together before you have anything.
Then as you go you can use those new tools to create other stuff. Sometimes replacing or rewriting those using new shit that you didn't have before.


-Bean
View user's profile Send private message Visit poster's website
NyanNyanKoneko
Contributor

Joined: 19 Oct 2005
Posts: 450
Location: In your L1 CPU cache
PostPosted: Sun Dec 02, 2007 8:32 am    Post subject: Reply with quote

OK, I'll throw up a basic vector review later today.

For now though, here's some pseudo-code for grabbing a normal off a triangle assuming the points are in CCW rotation. In 3D graphics, the normal is just the unit vector that points away from the face of a privative.

Code:

// Note, p0, p1, and p2 are all vectors that represent the 3 points of a triangle.
vector get_normal(p0, p1, p2)
{
  vector a;
  vector b;
  vector result;

  a = p1 - p0;
  b = p2 - p0;
 
  result = cross_product(a, b);

  return normalize(result);
}

View user's profile Send private message Visit poster's website
sonrisu
Moderator

Joined: 31 Aug 2005
Posts: 4998
Location: Silicon Valley!
PostPosted: Sun Dec 02, 2007 8:54 am    Post subject: Reply with quote

For those who aren't in the know, here is how you perform (as well as other goodness with) cross products.
View user's profile Send private message Visit poster's website
n29
Developer

Joined: 13 Sep 2005
Posts: 879

PostPosted: Sun Dec 02, 2007 10:00 am    Post subject: Reply with quote

Yeah, C!

Seems like you can get by with only sphere/plane or sphere/sphere intersection for most things until you want to fine grain collision detection (polygon/polygon) then the plane/plane stuff starts getting a little more complicated. I ran into this when clipping polygons to the view frustum in my software renderer. I took the easy path and just checked if each pixel was in/out of the screen. That's probably the least optimal solution.

I'm interested to see how you plan on incorporating scripting.
View user's profile Send private message
NyanNyanKoneko
Contributor

Joined: 19 Oct 2005
Posts: 450
Location: In your L1 CPU cache
PostPosted: Sun Dec 02, 2007 2:12 pm    Post subject: Reply with quote

All you need are point, spheroid, plane, ray, and frustum collision / distance detection, and you can derive everything else from that, including per-triangle model collision testing.

For example, let's take a simple object: a box. Create six planes (one for each side), and have the normal face inward. You have just defined an area inside the box. If all normals point toward a point, the point is inside the box.


Edited by NyanNyanKoneko on Fri Dec 07, 2007 2:12 pm; edited 1 time
View user's profile Send private message Visit poster's website
NyanNyanKoneko
Contributor

Joined: 19 Oct 2005
Posts: 450
Location: In your L1 CPU cache
PostPosted: Fri Dec 07, 2007 2:12 pm    Post subject: Reply with quote

Sorry for the lack of updates recently. I've been redoing my code since I decided to eventually sell this engine. One thing I was just working on was my memory-leak detection system.

Originally, I had my memory leak detection system create hooks into malloc, but it came up with a lot of false positives after calling OpenGL or SDL functions. So I decided to make a special version of the malloc functions.

Here are the malloc functions that are really necessary.
Code:

calloc(size_t block_size, size_t size); // Creates 'size' number of objects that are 'block_size' big.
malloc(size_t size); // Straight of memory allocation of 'size'. This can be used instead of calloc.
free(void *pointer); // Frees allocated memory.
realloc(void *pointer, size_t size); // This allows you to grow or shrink an array. It will copy over the former data if the pointer location changes.


Your specific standard C library may come with functions to allocate memory that is aligned to a value that you can specify. This may be useful for working with SSE intrinsic functions. BTW: You should use intrinsics over assembly if possible since the compiler knows how to optimize the intrinsic functions but not necessarily your assembly code.

Anyway, to track memory leaks, create your own versions of the functions above and add a counter. Since you don't want to run the debugging functions for the the final version of your product, you can tell the compiler to call the original malloc functions directly instead. Here's an example.

Code:

#ifdef DEBUGGING
void *my_malloc(size_t size);
#else
#define my_malloc(x) malloc(x)
#endif

int malloc_counter = 0;

#ifdef DEBUGGING
void *my_malloc(size_t size)
{
    malloc_counter++;
    return malloc(size);
}
#endif


You can obviously code more than a counter; you can create a linked list of all currently allocated memory and a description of each pointer (such as size and a string that describes the object). However, for most debugging tasks, simply knowing you're leaking memory is enough.

C++ people will want to make their own "my_new" and "my_delete" functions since it is ill advised to use malloc functions with classes. Malloc and free, for example, will not call constructors and destructors.
View user's profile Send private message Visit poster's website
Madgarden
Contributor

Joined: 31 Aug 2005
Posts: 324
Location: Kitchener, ON, CA
PostPosted: Fri Dec 07, 2007 8:30 pm    Post subject: Reply with quote

Sounds a little bit like Fortify, which I use from time to time. Works nicely.
_________________
I know it sounds crazy, but it JUST MIGHT WORK
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
sonrisu
Moderator

Joined: 31 Aug 2005
Posts: 4998
Location: Silicon Valley!
PostPosted: Sat Dec 08, 2007 8:07 am    Post subject: Reply with quote

Ah, yes. That good old malloc trick. Very useful. I'm actually surprised I haven't started using it in my own code. Hrm.

When are we going to be able to see some more of this stuff in action? Or, at least, some prospective list of the stuff available in the API?
_________________
loomsoft :]
View user's profile Send private message Visit poster's website
NyanNyanKoneko
Contributor

Joined: 19 Oct 2005
Posts: 450
Location: In your L1 CPU cache
PostPosted: Sat Dec 08, 2007 12:11 pm    Post subject: Reply with quote

sonrisu wrote:
Ah, yes. That good old malloc trick. Very useful. I'm actually surprised I haven't started using it in my own code. Hrm.

When are we going to be able to see some more of this stuff in action? Or, at least, some prospective list of the stuff available in the API?


The API is growing like a tree. There's no plan; once I finish something, I ask myself what I should do next. If I were constructing this like a building, I would have used C++ (another failing of object oriented programming languages). I don't know what it will look like in the end. Right now I'm just writing the mathematics routines, so it's a little boring.

Here's a quickie look at the source tree though. I expanded the linked list object so you can get a rough idea of how the API will be set up. It's very similar to allegro.



EDIT: Oh yeah, I added a boolean type, I should update the linked list code to reflect that. Some of the ints I pass into functions act as boolean values. ^_^
View user's profile Send private message Visit poster's website
NyanNyanKoneko
Contributor

Joined: 19 Oct 2005
Posts: 450
Location: In your L1 CPU cache
PostPosted: Sat Dec 08, 2007 12:50 pm    Post subject: Reply with quote

Anyway, back to planes. Here's an equation for a plane using a normal + point:

d = n dot_multiply p where n = normal of the plane and p = a point on the plane.

In other words: to get the variable d, do a dot product between the normal and a point on the plane.

Code:

vector normal;
vector point;
float d;

d = dot_product(normal, point);


And here's all the data you need to store a plane:

Code:

struct PLANE
{
    vector normal;
    float d;
};


And here's how to get the distance from the plane to a point, q:

Code:

vector q;
PLANE plane;
float distance;

distance = dot_product(q, plane.normal) - plane.d;


The distance is positive if it's in front of the plane, negative if behind, and 0 if it's on the plane.
View user's profile Send private message Visit poster's website
NyanNyanKoneko
Contributor

Joined: 19 Oct 2005
Posts: 450
Location: In your L1 CPU cache
PostPosted: Sun Dec 09, 2007 11:50 pm    Post subject: Reply with quote

So I got really bored doing math, so I decided to do something really important... add TTF support. I managed to load the font characters as textures, but I didn't make any printf functions for it yet.



Yay! Freetype isn't all that difficult to use, although the programmers don't label their typedef pointers as pointers though. I spent like 3 hours debugging this thing trying to get it to work.

View user's profile Send private message Visit poster's website
sonrisu
Moderator

Joined: 31 Aug 2005
Posts: 4998
Location: Silicon Valley!
PostPosted: Mon Dec 10, 2007 4:41 am    Post subject: Reply with quote

What is with the random dancing girl? Joy of getting TTF to work?

Also, I meant to ask this before; since you're going to be selling this: what is it going to have that's going to be worth the money over API/SDK's that people can download and use for free?
_________________
loomsoft :]
View user's profile Send private message Visit poster's website
NyanNyanKoneko
Contributor

Joined: 19 Oct 2005
Posts: 450
Location: In your L1 CPU cache
PostPosted: Mon Dec 10, 2007 10:43 am    Post subject: Reply with quote

You'll be able to use it for free for non-commercial use. Gliese is comparable to PTK, only Gliese is in C and does both 2D and 3D. The reason why Gliese is worth money is because it creates the basic framework needed for indie game development. Just like how allegro is a base for 2D games, Gliese will create similar base for 3D games. Gliese is kind of like a cross-platform DirectX system, supporting a unified package of 2D / 3D graphics, audio, networking, physics, scripting, and more.

It's also the only 3D game development library that isn't a "scenegraph" and not in C++. It gives you the tools to make your own scene graph. A 'Hello World' application in Gliese will only be one or two lines longer than a 'Hello World' application in Allegro. Of course, unlike Allegro, Gliese supports TTF fonts right from the get-go.

I mainly want it for myself, but if I can make some extra money off of it, I should. The only thing I don't like about Gliese is its long dependency list: SDL, SDL_Image, Lua, Freetype, OpenGL, OpenAL, Glu, Vorbis, Glew, etc...

Here's PTK's site: http://www.phelios.com/ptk/index.html

EDIT: If no one buys it, I'll just release it with a LGPL or BSD license.
View user's profile Send private message Visit poster's website
sonrisu
Moderator

Joined: 31 Aug 2005
Posts: 4998
Location: Silicon Valley!
PostPosted: Mon Dec 10, 2007 11:09 am    Post subject: Reply with quote

Hmm, I have never heard of PTK. Looks interesting. I still have to read more about it, though -- as of this writing I've only glanced at it quickly.

I'm surprised the licenses for all of those dependencies allow you to go so far as to make something (closed source?) that you are able to sell for money.
_________________
loomsoft :]
View user's profile Send private message Visit poster's website
NyanNyanKoneko
Contributor

Joined: 19 Oct 2005
Posts: 450
Location: In your L1 CPU cache
PostPosted: Mon Dec 10, 2007 11:24 am    Post subject: Reply with quote

What's so surprising? I've seen commercial applications make use of all those libraries.

SDL: LGPL
SDL_Image: LGPL
Glew: Modified BSD
Freetype: Freetype License
Lua: MIT License

And as for OGG Vorbis, OpenGL, and OpenAL, I've seen those used in lots of commercial libraries and applications as I'm sure you have, but I'm too lazy to look up their specific licenses.

Are you surprised that you can make a game using allegro or SDL and sell it for money? o_O Why should this be any different?

Besides, I'm helping the game-dev community as a whole by releasing it for free for private use. After enough time passes, it'll end up going open source anyway.

EDIT: I understand if your concerns are about me just repackaging SDL and making people pay me to use it. That would be sleazy. But it does take a lot of hard work to create a unified game development package, even when you're working off libraries like OpenGL or SDL. For example, getting freetype to work with OpenGL is not a trivial matter. You're not paying for SDL or any of the dependencies when and if you decide to use Gliese; what you're paying for is a license to use my code which binds everything together and gives game developers a framework to quickly begin their projects. In fact, per the request of the libraries, I'll add links to all the dependencies on the website and from the download.

I think I'm very fair in the way I wish to structure the licensing of Gliese. It's free for hobbyists, cheap for indie developers who want to make a profit off of it (like $20-$30 bucks), and quite a bit more expensive if someone like EA wants to use the engine.
View user's profile Send private message Visit poster's website
sonrisu
Moderator

Joined: 31 Aug 2005
Posts: 4998
Location: Silicon Valley!
PostPosted: Mon Dec 10, 2007 12:01 pm    Post subject: Reply with quote

Quote:
What's so surprising? I've seen commercial applications make use of all those libraries.

I don't know, maybe the fact that I haven't read all those licenses (nor do I want to) in order to determine whether they allow you to do such things or not. Also, I don't know all of the licenses for all of those libraries/APIs off the top of my head.

As for making a game using SDL and selling it for money: that is not surprising.

If I were going to attempt such an endeavor I'd be hard pressed to actually figure out all of the nitty gritty little technical details of all those licenses before they come back to bite me in the ass. I was just under the impression that at least one of them in that gigantic list of dependencies were the kind that requires you to release the source code in some way or another. Apparently I must be mistaken and there's a lot of stuff out there that gives you some pretty wide-range freedoms.
_________________
loomsoft :]
View user's profile Send private message Visit poster's website
NyanNyanKoneko
Contributor

Joined: 19 Oct 2005
Posts: 450
Location: In your L1 CPU cache
PostPosted: Mon Dec 10, 2007 12:32 pm    Post subject: Reply with quote

It's weird, but here's all you need to know. GPL makes you release all your source code if you use GPL code in your project or link to a GPL library. If I need to make a change to an LGPL library, then I need to release those changes, otherwise you don't need to release any source code when using an LGPL library. BSD-Style licenses are sort of free-for-all, no-strings-attached licenses.

Most libraries gravitate toward LGPL and BSD licenses since they are less restrictive and allow for commercial enterprise.

On LGPL:
Wikipedia wrote:
The main difference between the GPL and the LGPL is that the latter can be linked to (in the case of a library, 'used by') a non-(L)GPLed program, which may be free software or proprietary software [1]. This non-(L)GPLed program can then be distributed under any chosen terms if it is not a derivative work. If it is a derivative work, then the terms must allow "modification for the customer's own use and reverse engineering for debugging such modifications." Whether a work that uses an LGPL program is a derivative work or not is a legal issue. A standalone executable that dynamically links to a library is generally accepted as not being a derivative work. It would be considered a "work that uses the library" and paragraph 5 of the LGPL applies.

A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License.

Essentially, it must be possible for the software to be linked with a newer version of the LGPL-covered program.


So as long as the user links to SDL as opposed to me snatching code from SDL, you can use whatever license you want with the derivative software.
View user's profile Send private message Visit poster's website
sonrisu
Moderator

Joined: 31 Aug 2005
Posts: 4998
Location: Silicon Valley!
PostPosted: Mon Dec 10, 2007 12:37 pm    Post subject: Reply with quote

I guess what I meant to say, then, was that I figured one of those dependencies was under the GPL license. Guess not. :)
_________________
loomsoft :]
View user's profile Send private message Visit poster's website
JonA
Moderator

Joined: 24 Aug 2005
Posts: 396
Location: UK
PostPosted: Mon Dec 10, 2007 3:13 pm    Post subject: Reply with quote

A trivial question - where did the name come from?

--Jon
_________________
JonAtkinson.co.uk
View user's profile Send private message Visit poster's website
NyanNyanKoneko
Contributor

Joined: 19 Oct 2005
Posts: 450
Location: In your L1 CPU cache
PostPosted: Mon Dec 10, 2007 4:07 pm    Post subject: Reply with quote

JonA wrote:
A trivial question - where did the name come from?


Astronomy: Specifically Gliese 581c

The name is subject to change if anyone has a really good idea.

EDIT: I think the final name of the library will be libgs or GS Lib. Although, libgs already exists (ghostscript library). So if someone thinks of something good that GS could stand for, I'm all ears. :)

EDIT 2: So like, I think the final title will be: "Gliese: Gamedev Support Library - Explore New Worlds." AKA libgliese.a or gliese.lib for MSVC users.


Edited by NyanNyanKoneko on Mon Dec 10, 2007 4:25 pm; edited 5 times
View user's profile Send private message Visit poster's website
n29
Developer

Joined: 13 Sep 2005
Posts: 879

PostPosted: Mon Dec 10, 2007 4:12 pm    Post subject: Reply with quote

Hmmm, I was thinking that you only had to distribute your code if your changed code in a gpl project, like added your code to Apache to make 'n29Apache' or something. Seems like the requirement that dynamic linking make your code gpl as well is still a legal unknown.
View user's profile Send private message
Reply to topic GDR Forum Index -> Game Developer's Refuge -> Development Log - Gliese: Gamedev Support Library Page 1, 2, 3  Next

Use this link to get a Sign-On Bonus when you get started!

All trademarks and copyrights on this page are owned by their respective owners. All comments owned by their respective posters.
phpBB code © 2001, 2005 phpBB Group. Other message board code © Kevin Reems.