GM:S 1.4 3d Surfaces and projections

Discussion in 'Programming' started by NickKall, Jun 5, 2019.

  1. NickKall

    NickKall Member

    Joined:
    Mar 28, 2017
    Posts:
    67
    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
     
  2. Lonewolff

    Lonewolff Member

    Joined:
    Jan 8, 2018
    Posts:
    1,136
    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 likes this.
  3. NickKall

    NickKall Member

    Joined:
    Mar 28, 2017
    Posts:
    67
    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
     
  4. Lonewolff

    Lonewolff Member

    Joined:
    Jan 8, 2018
    Posts:
    1,136
    If you draw the surface 'tv_screen' on its own, do you get the expected output at that stage?
     
  5. NickKall

    NickKall Member

    Joined:
    Mar 28, 2017
    Posts:
    67
    haven't tried that yet. Give me ten minutes.
     
  6. NickKall

    NickKall Member

    Joined:
    Mar 28, 2017
    Posts:
    67
    Negative. It still draws a blank screen.
     
  7. Lonewolff

    Lonewolff Member

    Joined:
    Jan 8, 2018
    Posts:
    1,136
    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 likes this.
  8. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,088
    OP, I don't see where you are actually drawing anything to the surface. Did you edit out code from what you posted?
     
  9. NickKall

    NickKall Member

    Joined:
    Mar 28, 2017
    Posts:
    67
    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.
     
  10. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,088
    But you set a projection and then reset the render target without drawing anything to the surface in between.
     
  11. NickKall

    NickKall Member

    Joined:
    Mar 28, 2017
    Posts:
    67
    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?
     
  12. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,088
    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.
     
    Lonewolff and NickKall like this.
  13. NickKall

    NickKall Member

    Joined:
    Mar 28, 2017
    Posts:
    67
    It's so obvious when you put it like that.

    Thank you for making that clear.

    Nick
     
    Lonewolff likes this.
  14. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,088
    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.
     
  15. NickKall

    NickKall Member

    Joined:
    Mar 28, 2017
    Posts:
    67
    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?
     
    Lonewolff likes this.
  16. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,088
    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: Jun 6, 2019
    NickKall likes this.
  17. NickKall

    NickKall Member

    Joined:
    Mar 28, 2017
    Posts:
    67
    Ok. Thank you for you help.

    Nick:)
     
  18. Lonewolff

    Lonewolff Member

    Joined:
    Jan 8, 2018
    Posts:
    1,136
    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).
     
  19. NickKall

    NickKall Member

    Joined:
    Mar 28, 2017
    Posts:
    67
    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
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice