Legacy GM 3d Surfaces and projections

NickKall

Member
Hi all,

May I please ask for some help understanding what I am doing wrong?
(or if what I need can be done)

Please review the screenshot below
upload_2019-6-5_19-32-49.png

This is a view sitting on the pit wall of a race track. The white box directly in front of the view is supposed to be a TV screen showing footage from around the racetrack.

I have just learnt about surfaces. I tried to draw the projection footage from the other cameras onto a surface. That surface is then used as a texture to draw this polygon.

NOTE: when ran properly, the polygon is not visible at all. Only if I white it all out on refresh can I get this white screen.

Here is the code...

Code:
//Drawing to surface...
d3d_start()
surface_set_target(o_main.tv_screen)
draw_clear_alpha(c_white,1)
draw_set_alpha_test(true)     
d3d_set_culling(false) 
d3d_set_hidden(true)
d3d_set_zwriteenable(true)   
d3d_set_projection_ext(cam_from_x,cam_from_y,cam_from_z,cam_to_x,
            cam_to_y,cam_to_z,
                    0,0,1,45,1280/720,1,5000)
surface_reset_target()

//Drawing to screen
d3d_start()
draw_set_alpha_test(true)     
d3d_set_culling(false) 
d3d_set_hidden(true)
d3d_set_zwriteenable(true)   
d3d_set_projection_ext(man_camf_x,man_camf_y,man_camf_z,man_camt_x,man_camt_y,man_camt_z,
                    0,0,1,45,1900/1000,0.1,5000)

//Drawing the TV
d3d_transform_set_identity()
d3d_transform_add_rotation_z(270)
d3d_transform_add_translation(man_camf_x,man_camf_y,man_camf_z)
draw_set_colour(c_white)
tex_tv = surface_get_texture(tv_screen)
d3d_model_draw(tv_model,0,0,0,tex_tv)
d3d_transform_set_identity()
Thank you in advance for any help anyone may have.

Nick
 

Lonewolff

Member
Code:
tex_tv = surface_get_texture(tv_screen)
Here you refer to 'tv_screen', but you initially draw to 'o_main.tv_screen'.

Are you sure you are referencing the right surface?
 

NickKall

Member
Code:
tex_tv = surface_get_texture(tv_screen)
Here you refer to 'tv_screen', but you initially draw to 'o_main.tv_screen'.

Are you sure you are referencing the right surface?
Oops. That is just an oversight from when I was trying to put that projection in a different object. This code is in the object called o_main.

Thank you
 

Lonewolff

Member
I'd certainly look in to that then.

I recommend commenting out the other stuff and get your TV screen drawing to the full screen first. After that, it should all fall in to place.

Code:
//Drawing to surface...
d3d_start()
// surface_set_target(o_main.tv_screen)
draw_clear_alpha(c_white,1)
draw_set_alpha_test(true)     
d3d_set_culling(false)
d3d_set_hidden(true)
d3d_set_zwriteenable(true)   
d3d_set_projection_ext(cam_from_x,cam_from_y,cam_from_z,cam_to_x,
           cam_to_y,cam_to_z,
                   0,0,1,45,1280/720,1,5000)
// surface_reset_target()

// ^^^^ Just get this part to draw properly first

/*
//Drawing to screen
d3d_start()
draw_set_alpha_test(true)     
d3d_set_culling(false)
d3d_set_hidden(true)
d3d_set_zwriteenable(true)   
d3d_set_projection_ext(man_camf_x,man_camf_y,man_camf_z,man_camt_x,man_camt_y,man_camt_z,
                   0,0,1,45,1900/1000,0.1,5000)

//Drawing the TV
d3d_transform_set_identity()
d3d_transform_add_rotation_z(270)
d3d_transform_add_translation(man_camf_x,man_camf_y,man_camf_z)
draw_set_colour(c_white)
tex_tv = surface_get_texture(tv_screen)
d3d_model_draw(tv_model,0,0,0,tex_tv)
d3d_transform_set_identity()
*/
 

NickKall

Member
OP, I don't see where you are actually drawing anything to the surface. Did you edit out code from what you posted?
The first 11 lines is where I am drawing to the surface. It is a 3d projection.

The Next group is then drawing another 3d projection.

The last group is where I draw the polygons that use the surface as a texture.
 

NickKall

Member
d3d_start()
surface_set_target(o_main.tv_screen) <<< Setting the target to the surface
draw_clear_alpha(c_white,1)
draw_set_alpha_test(true)
d3d_set_culling(false)
d3d_set_hidden(true)
d3d_set_zwriteenable(true)
d3d_set_projection_ext(cam_from_x,cam_from_y,cam_from_z,cam_to_x, <<< Drawing the projection to the target surface
cam_to_y,cam_to_z,
0,0,1,45,1280/720,1,5000)
surface_reset_target() <<<< Resetting the target

Have I missed something?
 
I think the confusion probably came from being used to letting gamemaker handle the order in which things are drawn using drawn events. But in 3d, you are probably going to want to set all of that aside, and control drawing from a single draw event, so that you can be completely sure the order in which drawing related operations are performed.
 

NickKall

Member
I have found some problems already.

upload_2019-6-6_10-1-17.png

The garage and cars are not visible on the surface (tv screen at bottom).

The items that cannot be seen on the screen are seperate object with a depth below the camera object.

The 2 different camera views are drawn one after the other.

Would it be better if I drew the tv view projection, take a screen shot of that, draw that screenshot to the surface, then draw the new view in the one step?
Or am I being lazy?
 
If I were you I would move all of my drawing (related to 3d) to a single control object, instead of having it spread out between multiple objects. It's just so much easier.

Whatever you want to be visible in your tv view, you need to draw it in that view. Which means you'll need to draw everything in your 3d world twice. Once for the main view, and once for the tv view.
 
Last edited:

Lonewolff

Member
d3d_start()
surface_set_target(o_main.tv_screen) <<< Setting the target to the surface
draw_clear_alpha(c_white,1)
draw_set_alpha_test(true)
d3d_set_culling(false)
d3d_set_hidden(true)
d3d_set_zwriteenable(true)
d3d_set_projection_ext(cam_from_x,cam_from_y,cam_from_z,cam_to_x, <<< Drawing the projection to the target surface
cam_to_y,cam_to_z,
0,0,1,45,1280/720,1,5000)
surface_reset_target() <<<< Resetting the target

Have I missed something?
Yes.

Set a render target.

Then set a projection.

Then draw something.

Then reset the render target.

Setting a projection doesn't do anything except set the current projection and view matrices. It doesn't draw anything.
Sorry man, I didn't even point out that you had nothing rendering in there as you seem to have a good grasp of how things draw etc, considering you are tackling a 3D project (and seem to be going very well with it I might add).
 

NickKall

Member
That's alright Sorcerer. These things pass by me sometimes. I lay carpets for a living. I started learning GML say 5 years ago in my spare time. GML is the only language I know. Learnt only from the Help guide, youtube videos, articles online and helpful people on this forum.

Thanks
Nick
 
Top