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)



Jan
31

GM6 D3D from the Ground Up - Chapter 2

2007 @ 10:17 PM

Chapter 2 - Introduction to D3D Programming

I'm sure you have a firm understanding of our we can accomplish 3D drawing now. So, let's actually get into the real action.

Getting into 3D Mode

To do any 3D drawing in Game Maker, we must first set it into 3D mode. We can accomplish this by using the d3d_start() function. Use the d3d_end() function to put GM back into 2D mode.
Upon calling d3d_start(), Game Maker automatically enable hidden surface removal. Hidden surface removal is a way to ensure that everything is drawn in the correct order. Whenever a pixel is drawn, it's assigned a value in the z-buffer that describes its distance from the viewer's perspective. Whenever another pixel needs to be drawn in that same location, D3D tests to see if this new pixel's z-buffer value is closer of further away from the viewer. If it is closer, it overwrites the old pixel. Otherwise, the new pixel is never drawn. However, there sometimes arises a special case where the z-buffer values are the same. This is called z-clipping. It is undefined as to what D3D draws and therefore you get some ugly results. You can toggle the z-buffer and hidden surface removal via the function d3d_set_hidden({true|false});
Next, Game Maker automatically turns off the Orthographic projection and turns on the Perspective projection. You can toggle between the orthographic and perspective projections via the function d3d_set_perspective({true|false});

Hello, 3D World!

Let's write a skeleton 3D application. Our goal is to simply set Game Maker into 3D mode.
Start a new Game Maker project and save it as "hello.gm6". Create a new object and name it "d3dController." This object will be used to execute code to put GM into 3D mode.
Right-click on "d3dController" and select "Properties..." Click on the "Add Event" button in the Object Properties dialog and click on the "Create" event.
Next, select the "Control" tab. Drag and Drop the "Execute a piece of code" library action into the "Actions:" list.
The GM code editor should show itself. Add the following code:
d3d_start(); //Initializes 3D mode
Now create a new room and add this object to it.

Drawing Some Shapes

Add a "Draw" event to our object. Again, add a new Code Execution action. We're going to simply draw a rectangle on the screen.
d3d_set_projection_ortho(0,0,room_width,room_height,0);
draw_set_color(c_red);
draw_rectangle(30,30,60,60,true);
The only unfamiliar code should be the d3d_set_project_ortho function. However, you should have an idea of what it does already. Hopefully, you've guessed that it defines an othographic projection for Direct3D to project our coordinates to. If you recall, orthographic projections are for drawing text and images. So, you can use the familiar draw_rectangle function here.

d3d_set_projection_ortho

Synopsis: d3d_set_projection_ortho(x, y, w, h, angle); The function creates an orthographic projection over the specified viewing volume in the room. It is then rotated over the given angle. In our example, we just used the room's width and height. However, you could bind it to only a certain part of the window.

<< 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