Where to start?

Previous topic - Next topic

Hatonastick

Hi guys, I'm looking to get back into programming and am going to bite the bullet and work (slowly) on my first 3D project (in GLB that is, I had a bit of a play with the simple commands in GM some time back).

I'm aiming to remake what is in this GM test program first.  The main bits that worry me are: a) the wireframe grid, which was very easy to create in GM using its version of X_OBJ but doesn't look so easy to do in GLB (textured fake grid is not an option as it tends to pixelise at certain resolutions -- tried once in GM), and b) the lighting (not that the spheres are going to be flat in the GLB version).  The grid is actually just a box shape (4 lines that make up a wireframe square) that is copied into 2 10x10 grids (one for the floor, once for the ceiling) which are moved about as the player object moves.  Is OpenGL capable of just drawing lines or does everything have to be a triangle?  Actually this will be important to know for some of the object shapes I want to use.  For style of graphics, think Interphase (old Atari ST game, which this game will have some things in common with -- albeit simpler).  Hmm speaking of which, and looking at screenshots of that game, it might be easier to get away with some filled in squares (not joined) as the ground and ceiling.  I might end up having to make all my objects in a 3D CAD program, which isn't what I wanted to do as I was hoping to go procedural.  Could turn out to be somewhat easier though.

Anyway with this ultra simple example in GM (was just working out the basics of how I could approach things), the controls are mouse for turning, with standard WSAD FPS movement.  The console is broken in this version so don't push the ~ key unless you want to fill the screen up with the keys you push.  I did have a version with on-the-fly 3D lightning between the balls, but not sure where that one went.

While my game will share some things in common with Interphase, it wont be a remake.  For starters the puzzle elements will be totally different -- there will also be a limited form of interaction in the game with other players via my web server.  The only real similarities will be theme and the graphical style.  It's sort of a cross between Interphase and an old BBS door game called Netrunner.   A game I've always wanted to make but never have despite having various stage WIPs in everything from GM, to Blitz3D, BlitzMax, C and PureBASIC.  Then there's the PureBASIC ASCII hack version which didn't get past the stupid animated character intro (I spent too much time creating an animated ASCII graphics macro language interpreter called Termination instead of working on the actual game).  Ugh.

Well I recently broke my long standing 'create character, delete, restart, delete, restart and never see the end of the game' record with MMOs (something my friends never thought would happen in their lifetimes).  Time to break my 'never get past simple, partial WIPs or design notes' computer game creation drought...  Mind you if I do manage to do that, the universe will probably end.  After all it would be the breaking of a 26 year old habit.

Would a kind moderator please move this to my blog thing?  I just realised that it's probably more suitable to have this post there than here.  Thanks.

[attachment deleted by admin]

Hemlos

I never used or saw GM, however, i think you mean Game Maker(no?).
IF you just need a cube of lines to surround the object..
I made a function called X_DRAWBOXAXES, found on this page in the 3d section:
http://www.glbasic.com/forum/index.php?topic=3603.0

Full 3d object wireframes can be done in three ways, that i know of...
I think the opengl wireframe mode will be fastest, but i dont know how flexible it is in manipulating color or position.
You can find this method here:
http://www.glbasic.com/forum/index.php?topic=3730.0

Another way using 3d lines and getface, which outlines all the triangle surfaces.
This method is slower(if you have hundreds of lines), but allows you to manipulate color and positions.
You can download the source for the "3d object analyzer" from the showroom.
It is called edge mode in that program, beware, this is very sophisticated (i dont recommend this method if you are looking for a quick learning curve).

Using textures MIGHT be an option, but i am assuming this is probably going to have to be UV mapped in a 3d object creation program.


Goodluck,
-Neil
Bing ChatGpt is pretty smart :O

FutureCow

Having almost finished my first 3D project (my board game competition entry), I think I can be of help here.

As far as I'm aware, everything must be created as triangles (you can create a quad for example as per below, but it's actually just 2 triangles where 2 of the verticies are shared) as graphics cards work with triangles. So even if OpenGL has support for non-triangles, my money is on it making triangles in the background regardless.

If you want a wireframe 2D grid, do it like this :-
Basically you create a 3D object that is a series of 2D squares, apply a texture that is a square with a transparent  middle, and Bob's your uncle.

Code (glbasic) Select
SUB CreateGrid:
GridObj=GENX_OBJ()
X_OBJSTART GridObj
FOR Z=0 TO GameBoardSizeY-1
FOR x=0 TO GameBoardSizeX-1
X_OBJNEWGROUP // Create a new group of polygons every row
X_OBJADDVERTEX   x,   0, Z+1, 0, 0, RGB(255,255,255) // Create quad
X_OBJADDVERTEX   x,   0, Z  , 0, 1, RGB(255,255,255)
X_OBJADDVERTEX   x+1, 0, Z+1, 1, 0, RGB(255,255,255) // Create quad
X_OBJADDVERTEX   x+1, 0, Z  , 1, 1, RGB(255,255,255)
NEXT
NEXT
X_OBJEND
ENDSUB // CREATEGRID


Load your texture (mine is attached) - you'll notice it's a square with the transparent colour in the middle.
Code (glbasic) Select

I_GridTexture = GENSPRITE()
LOADSPRITE "GridTexture.png", I_GridTexture


Once you've done that, set your texture to be the active texture, then draw your object.
(As previously mentioned, at this point you inherit an Uncle Bob if you didn't already have one).
Code (glbasic) Select
X_SETTEXTURE I_GridTexture,-1
X_DRAWOBJ GridCollisionObj,0


If you have troubles with pixellation, try increasing the size of the texture to say 1024x1024 - that should help get rid of some roughness.

If however you want a 3D grid (as opposed to the above 2D grid in 3D space) you modify the above to use a cube rather than a square. I don't have full code for doing this, but I do have my code for creating a rectangular prism, so it should be easy to replace the square creation above with it and get a cube grid pretty quickly. (I would write the code, but I'm leaving that as an exercise for the reader  >:D )

Code (glbasic) Select
// ------------------------------------------------------------- //
// -=#  CREATERECTANGULARPRISM #=-
// ------------------------------------------------------------- //
FUNCTION CreateRectangularPrism: num, Length, Width, Height, col
//         +----+
//         /   /|
//        /   / |
//       /   /  |
//      /   /   |
//     /   /    |
// H  +---+     /  h
// e  |   |    /  t
// i  |   |   /  g
// g  |   |  /  n
// h  |   | /  e
// t  |   |/  L
//    +---+
//
//   Width

   X_OBJSTART num
      // Front Face
      X_OBJADDVERTEX  Width,       0,  Length, 1, 0, col
      X_OBJADDVERTEX      0,       0,  Length, 0, 0, col
      X_OBJADDVERTEX  Width,  Height,  Length, 1, 1, col
      X_OBJADDVERTEX      0,  Height,  Length, 0, 1, col
      X_OBJNEWGROUP
      // Back Face
      X_OBJADDVERTEX      0,  Height,       0, 1, 1, col
      X_OBJADDVERTEX      0,       0,       0, 1, 0, col
      X_OBJADDVERTEX  Width,  Height,       0, 0, 1, col
      X_OBJADDVERTEX  Width,       0,       0, 0, 0, col
      X_OBJNEWGROUP
      // Top Face
      X_OBJADDVERTEX      0,  Height,  Length, 0, 0, col
      X_OBJADDVERTEX      0,  Height,       0, 0, 1, col
      X_OBJADDVERTEX  Width,  Height,  Length, 1, 0, col
      X_OBJADDVERTEX  Width,  Height,       0, 1, 1, col
      X_OBJNEWGROUP
      // Bottom Face
      X_OBJADDVERTEX  Width,       0,       0, 0, 1, col
      X_OBJADDVERTEX      0,       0,       0, 1, 1, col
      X_OBJADDVERTEX  Width,       0,  Length, 0, 0, col
      X_OBJADDVERTEX      0,       0,  Length, 1, 0, col
      X_OBJNEWGROUP
      // Right face
      X_OBJADDVERTEX  Width,  Height,       0, 1, 1, col
      X_OBJADDVERTEX  Width,       0,       0, 1, 0, col
      X_OBJADDVERTEX  Width,  Height,  Length, 0, 1, col
      X_OBJADDVERTEX  Width,       0,  Length, 0, 0, col
      X_OBJNEWGROUP
      // Left Face
      X_OBJADDVERTEX      0,       0,  Length, 1, 0, col
      X_OBJADDVERTEX      0,       0,       0, 0, 0, col
      X_OBJADDVERTEX      0,  Height,  Length, 1, 1, col
      X_OBJADDVERTEX      0,  Height,       0, 0, 1, col
      X_OBJNEWGROUP
   X_OBJEND
ENDFUNCTION // CREATERECTANGULARPRISM



Link X_ROTATION to the mouse, and X_CAMERA to WASD, and that should cover that bit.

Lighting is also a bit confusing (at least it was to me). Without any explicit light sources at all your scene will be lit (I've got no idea why, just go with the flow). Introducing an ambient light, even a white ambient light (RGB 255,255,255) to your scene will see all your colours dim (someone explained it to me I think in reply to my question on the forum, but I can't remember - it seems stupid and counter-intuitive to me!!) Anyhoo, I'm not sure about the lighting without the original demo to see what you're trying to replicate, but hopefully just add a couple of spotlights (X_SPOT_LT) and you'll be cooking with gas.


[attachment deleted by admin]

Hatonastick

Ok thanks guys!  You've given me a lot to think about and work my way through!  Actually I hope now no-one else will post for a while as it really is going to take me quite some time to get my head around all this (depending on how 'awake' I am at the time -- it still takes me a while for the engine in my brain to warm up).  :)

And in answer to your question Hemlos, GM does indeed refer to Game Maker.

Thanks again to both of you for your help!