drawing black after 3d game maker

It goes without saying that almost every game programmer probably started out wanting to brand games in 3D. Subsequently all, practically all of the AAA games that we played growing up were in 3D, so it comes as no surprise that nosotros desire to create our ain 3D wonderworks.

What yous may or may not realize is that the apprehensive Game Maker comes with the power to draw 3D graphics. This makes the task of putting 3D games together a lot simpler. All the same, one thing I would like to emphasize early is that 3D is simply some other tool – nothing more, zippo less. Giving a game 3D graphics will not magically make it better. In fact, it tin complicate a design that would otherwise piece of work perfectly well in second. Conversely, using 3D in GM tin also simplify certain graphical aspects of your game. It'south upwards to you to decide whether it's worth all the extra effort, and to be aware of the limitations of Game Maker's 3D functions.

Comport in heed that GM'due south 3D functions are fairly simplistic. GM is a second game engine with some 3D graphics functions slapped in for skilful measure. You lot'll also need to be quite familiar with GML scripting, since 3D is beyond the scope of the drag 'n' drop beginner'southward interface.

Furthermore, before you lot go all excited, have note – Game Maker does NOT do the following:

  • Shaders. Forget about it.
  • 3D movement and positioning calculations. Remember that even though information technology's rendering in 3D, GM nevertheless operates on a 2 dimensional plane under the hood. If you want to build an FPS where you can burn projectiles up and down as well as horizontally, you'll have to be prepared to script your own lawmaking to accept things position and movement properly in 3D. GM doesn't do it for you out of the box. Y'all'll be fine for two.5D games though.
  • Accurate 3D polygonal collision detection. GM doesn't practice this for you, nor does it give you direct access to mesh data or the matrix functions you'd need to implement it yourself. There are ways to exercise collision detection, merely not on a per-polygon footing. This makes 3D level design specially finicky.
  • Intelligent rendering. Most 3D game engines have fancy code running under the hood to ensure that they only depict what they need to, instead of lobbing every polygon in the scene at the graphics bill of fare and slowing things down to slideshow speeds. GM doesn't do this. Depending on the complication of your rendered scene, you may have to implement your ain system to prevent unwanted objects from existence drawn.
  • Fancy 3D modelling and blitheness. While scripts exist for you to import 3D models, and fifty-fifty build animations, GM (say it with me) does not back up this out of the box.

I should note that if you lot search the Net hard plenty, y'all can find scripts and stand up-alone engines that you tin can plug into a GM game to give it the to a higher place functionality. These vary in quality and ease of use, and autumn exterior the telescopic of this tutorial.

Okay, plenty disclaimers and doomsaying. Allow'south see what this thing can do. This tutorial will guide yous through setting up a basic 3D scene, and prove you what commands are available and how they're used.

The photographic camera

The camera is your window into the 3D world, so it makes sense that nosotros cover it first. Without the photographic camera, GM won't know from which viewpoint yous desire your 3D globe to be rendered, and give you a bizarre upside-downwards default view. Equally such, information technology helps to have a core camera object from which you lot can control the 3D viewpoint. Your implementation may differ, but I by and large similar to put all of the 3D initialization stuff into the photographic camera object too, since it keeps information technology in one logical and convenient place.

The get-go thing we need to do to go our 3D game up and running is to initialize 3D mode. We'll do this in our photographic camera object. Here's a sample of the code that goes into the Create event of my photographic camera object:

//Start 3D mode d3d_start();   //Enable lighting d3d_set_lighting(true);   //Enable backface culling. This stops the renderer from drawing polygons that //face away from the camera, speeding the render up. d3d_set_culling(true);   //Ascertain and enable a global directional light. Nosotros won't go into the details //correct now, only I will comprehend this in a later tutorial. d3d_light_define_direction(1,one,0.5,0,c_white); d3d_light_enable(ane,true);

And that does it for your initialization. The next exciting fleck will exist in your Draw event:

d3d_set_projection(ten,y,0,x+20,y,0,0,0,1);

This do-all part specifies where your photographic camera will be placed, and where it will exist pointing. And that's information technology. Using the data you give that function, GM will render the scene. Quick and easy. For at present, the above code will point the camera to the correct of wherever it'southward placed. Obviously, y'all tin can supersede the constants here with whatever variable you like, allowing you lot to alter the viewpoint however you crave. I recommend playing with these variables by yourself once y'all've got this tutorial lawmaking up and running, to get a amend idea of what they do.

Camera settings

Photographic camera settings

Ane terminal thing. In 3D mode, it is incredibly of import that you have note of the club in which things are drawn, particularly the camera. The camera must e'er be drawn first. No exceptions. So how do you control this? Simple – the "depth" variable that comes role of every GM object yous create. If you've played with it in 2D mode, you'll know that objects with higher depths are candy and drawn outset. Equally such, information technology's good to set your camera object'due south depth to a really high number to ensure that it goes first (I tend to apply 10000000 or so). If your 3D scene draws itself from a top-down perspective instead of from the camera, that's a sure sign that the draw guild is out.

Drawing 3D primitives

Now that we have a camera to return stuff from, we demand something to point it at. Normally this would involve a whole lot of 3D modeling. Fortunately, GM comes with a set of functions that allows you to render a selection of 3D primitives using nothing just a single line of code. Let's take a look.

To offset off with, we'll depict a good quondam cube. Create an object chosen "Cube", and identify the following in its Draw event.

draw_set_color(c_white); d3d_draw_block(x-16,y-16,-sixteen,x+16,y+sixteen,xvi,-1,i,1);

Firstly, we demand to define the color that our archaic is drawn in. Nosotros do this using the good erstwhile draw_set_color() office that we use in 2D. Information technology'due south important to set up the color starting time, because otherwise our polygons will be drawn in blackness by default – non the finest color for 3D objects to be.

Cone!

Cone!

The second line contains the command to describe a cube. The start 6 arguments allow you to ascertain the dimensions of the cube, using two sets of 10,y,and z variables that you lot want your cube to exist describe between. Using these, yous can control the proportions of your cube. The terminal three arguments are used for texture mapping. Since we don't accept a texture at the moment, we'll set the texture to -1, and the concluding two variables to one. Don't worry – when we eventually delve into texture mapping, I'll permit you know how they work.

Ellipse!

Ellipse!

There are other primitives that you can depict in a very similar way. Once you take this tutorial code upward and running, try playing with the following functions: d3d_draw_floor(), d3d_draw_wall(), d3d_draw_cone(), d3d_draw_cylinder(), and d3d_draw_ellipsoid(). You can notice out more nigh them in the GM help file.

Rendering!

Adjacent, put your Camera and Wall objects in a room. Set the room background to a colour that won't interfere with the visibility of your cube. Then identify your camera, and place your cube object to the right of it (since we've set the camera to betoken to the correct of where it's placed).

Room setup

Room setup

So run the game! You lot should see a grey square rendered in front end of the camera! That's one face of your cube! Try altering the positioning arguments of the d3d_set_projection() function to get dissimilar views of the cube.

That'due south it for this month! Until next outcome, try playing around with using different primitives, and experiment with positioning and orienting the camera. Adjacent issue, nosotros'll look at rotating and transforming 3D objects, and detect out a petty bit more than about lighting. Until so!

andersonfropeorcee.blogspot.com

Source: http://devmag.org.za/2009/04/05/3d-graphics-in-game-maker-part-1/

0 Response to "drawing black after 3d game maker"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel