home · software · code · tutorials · site map

3664
Congressman warns of current GA- Russia conflict in 2002!!!
Ron Paul in an interview with Jim Lehrer says in 2002 interview that by the US adopting a preemptive first Strike Doctrine would eventually lead to Russia invading GA
3552
Girls Get the Anime Look with Extra-Wide Contact Lenses
Girls in Japanese comics, cartoon videos or anime share a common look - big eyes that, by making the rest of the face look small, add the cuteness and sex appeal prized by many Japanese men. Since no amount of cosmetic surgery will make actual human eyes larger, some girls are trying another way to up their cute quotient: extra-wide contact lenses!
1262
'Everyone Will Remember Me as Some Sort of Monster'
A troubled teenager. An assault rifle. Eight slain in a mall. It was national news for a few days. Then it was forgotten.
822
Repurpose Your Nintendo as a Lunchbox (PICS)
I had a broken NES, a rotary tool, two small hinges, some glue and Alpha Flight's Sasquatch. What I ended up with was a lunchbox that gets all kinds of funny looks.
3104
Once You Look, You Can't Look Away (Pic)



Feb
2

GM6 D3D from the Ground Up - Chapter 6

2007 @ 12:45 PM

Chapter 6 - Blending and Basic Shapes

Blending

Blending is simply blending colors together. For example, you can draw background objects and then blend a window on top of them to create a translucency effect. There are many different ways to blend colors, however, not just adding them together.

Combining Colors

The color value that is already stored in the color buffer is called the destination color. The source color is the color coming in due to new rendering commands. To activate a blending mode, you can use the function draw_set_blend_mode(mode). Several different modes exist: bm_normal, bm_add, bm_subtract, and bm_max. You must not forget to reset the blending mode to bm_normal when you're done drawing the blended object, however.

Drawing Basic Shapes

Game Maker has functions that simplify some commonly used 3D shapes for us. You can draw blocks, cylinders, cones, ellipsoids, walls, and floors with the commands. The shapes already have their normals and texture coordinates defined, so you don't have to worry about that. The functions follow an easy to use convention - specify the dimensions and a few special parameters for certain shapes(E.G., closed for the cone shape to specify whether or not to close the end of it). Check the Game Maker manual's page on Drawing Basic Shapes for a complete function reference.

Practical Example

Let's use what we have learned on blending and Game Maker's basic shapes to create a fake reflection.
draw_set_color(c_red);
d3d_draw_block(x-15,y-15,40,x+15,y+15,10,-1,0,0);
//Reflect Block and Light
d3d_light_define_point(2,d3dController.x,d3dController.y,-50,1024,c_white);
d3d_draw_block(x-15,y-15,-10,x+15,y+15,-40,-1,0,0);
draw_set_blend_mode(bm_add);
d3d_set_lighting(false);
draw_set_color(c_blue);
d3d_draw_floor(0,500,0,500,0,0,-1,0,0);
d3d_set_lighting(true);
draw_set_blend_mode(bm_normal);
d3d_light_define_point(2,d3dController.x,d3dController.y,10,1024,c_white);
reflection
That's not a bad result, eh?
The first thing we do is draw a block using the function d3d_draw_block(x1,y1,z1,x2,y2,z2,texid,hrepeat,vrepeat). Disregard the texid, hrepeat, and vrepeat arguments for now. Those all have to do with textures, which will be covered soon. Next, we draw the reflected cube below the floor. We also reflect the light below the floor. Next we set the blending mode to bm_add with draw_set_blend_mode. We also disable lighting so it doesn't affect our blending. We then draw the floor which is blended with the reflected cube. After doing that, we reset the blending mode, reenable lighting, and move our light back to where it was.
As you can see, this isn't the most efficient nor elegant way to draw reflections. Everything reflected has to be drawn twice: once above and once below the floor. Combine that with a blending operation and you can really slow your game down.

Other Basic Shapes

Consult the Game Maker manual and play around with the different types of primitives. They're all very simple to use and can be very useful.

<< Previous Chapter      Next Chapter >>


 Del.icio.us  Digg  Furl  Google  Reddit  Slashdot


This article hasn't been commented yet.

CommentsWrite a comment

:

:

:

Blogtastic RSS FEED

Linktastic


TysonC's Profile Page