Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a 3D rendering context with non-default properties breaks Vector:ToScreen() #1404

Open
willox opened this issue Aug 9, 2014 · 1 comment

Comments

@willox
Copy link
Contributor

willox commented Aug 9, 2014

hook.Add("PreDrawHUD", "", function()

    cam.Start3D(nil, nil, 20) -- Create and destroy a 3D rendering context with a FOV of 20
    cam.End3D()

    cam.Start2D()
        -- This call to ToScreen thinks that the screen's FOV is 20
        local pos = Vector(0, 0, 0):ToScreen()
        local x, y = pos.x, pos.y

        surface.SetDrawColor(Color(255, 0, 0))

        surface.DrawRect(pos.x - 16, pos.y - 16, 32, 32)
    cam.End2D()



    cam.Start3D() -- Create and destroy a default 3D rendering context
    cam.End3D()

    cam.Start2D()
        -- This call to ToScreen thinks that the screen's FOV is its real value
        local pos = Vector(0, 0, 0):ToScreen()
        local x, y = pos.x, pos.y

        surface.SetDrawColor(Color(0, 255, 0))

        surface.DrawRect(pos.x - 16, pos.y - 16, 32, 32)
    cam.End2D()

end)

This example shows the issue by modifying the FOV, but changing any parameter to Start3D will cause this.

The confusing thing about this is that in some cases it is optimal behaviour, but usually it isn't.

@DBotThePony
Copy link

DBotThePony commented May 1, 2016

Any updates?
This bug forces DModelPanel to break ToScreen() waht called after model is drawn
https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/vgui/dmodelpanel.lua#L151

Update:
Calling

cam.Start3D() 
cam.End3D()

with no arguments after panel is drawn will fix ToScreen()

2016-05-01_09-16_h-srv-gm_test-garrysmod-addon
2016-05-01_09-16_garry s mod
2016-05-01_09-16_h-srv-gm_test-garrysmod-addon 2

Removing cam context
2016-05-01_09-17_h-srv-gm_test-garrysmod-addon
2016-05-01_09-18_garry s mod

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants