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

Matrix poping inside cam.Start3D2D #1663

Closed
Nak2 opened this issue Dec 19, 2014 · 14 comments
Closed

Matrix poping inside cam.Start3D2D #1663

Nak2 opened this issue Dec 19, 2014 · 14 comments
Labels
Bug The issue is confirmed to be a bug and not intentional behaviour.

Comments

@Nak2
Copy link

Nak2 commented Dec 19, 2014

Calling cam.PushModelMatrix and cam.PopModelMatrix inside cam.Start3D2D broke.
Example:
image

function draw.TextRotated( text, x, y, color, font, ang )
    render.PushFilterMag( TEXFILTER.ANISOTROPIC )
    render.PushFilterMin( TEXFILTER.ANISOTROPIC )
    surface.SetFont( font )
    surface.SetTextColor( color )
    surface.SetTextPos( 0, 0 )
    local textWidth, textHeight = surface.GetTextSize( text )
    local rad = -math.rad( ang )
    local halvedPi = math.pi / 2
    x = x - ( math.sin( rad + halvedPi ) * textWidth / 2 + math.sin( rad ) * textHeight / 2 )
    y = y - ( math.cos( rad + halvedPi ) * textWidth / 2 + math.cos( rad ) * textHeight / 2 )
    local m = Matrix()
    m:SetAngles( Angle( 0, ang, 0 ) )
    m:SetTranslation( Vector( x, y, 0 ) )
    cam.PushModelMatrix( m )
        surface.DrawText( text )
    cam.PopModelMatrix()
    render.PopFilterMag()
    render.PopFilterMin()
end

---------- Entity Draw ----------
cam.Start3D2D( self:LocalToWorld(Vector(0,0,14.6)), self:GetAngles(), 0.08 )
    -- Table ring --
    local size = 630
    local C = Color(0,255,125)
    surface.SetMaterial(Mat[1])
    surface.SetDrawColor(C)
    surface.DrawTexturedRect(-size*n/2,-size*n/2,size*n,size*n)

    -- Text --
    surface.SetTextColor(C)
    surface.SetTextPos(0,0)
    surface.SetFont("CardFontData")

    surface.DrawText("I work")
    draw.TextRotated("But I don't",0,0,Color(255,255,255),"CardFontData",90)

cam.End3D2D()
@robotboy655
Copy link
Contributor

Does it work in "live branch"?

@Nak2
Copy link
Author

Nak2 commented Dec 27, 2014

If by "live branch" you mean "dev - development branch" .. then no.
http://cloud-4.steampowered.com/ugc/40862758531587724/17D099F5FD2942D6055746227D3C131966934FF3/
It works when you run it in the HUDPaint, but for some strange reason it's popping outside the render when its in cam.Start3D2D. My guess is the render order messes with it.

@robotboy655
Copy link
Contributor

No, not the dev branch, the no beta version of the game.

@Nak2
Copy link
Author

Nak2 commented Jan 15, 2015

I've tried in many ways to render cam.PopModelMatrix inside a 3D render-environment but with no luck.
I tried the beta- and live-version of the game and tried to render it in ENT:Draw and outside in render.hooks.
Something breaks the VMatrix rendering when its not inside a 2D-environment.

@robotboy655
Copy link
Contributor

Does it work properly in live version?

@Nak2
Copy link
Author

Nak2 commented Jan 15, 2015

No. I got a suspicion that cam.PopModelMatrix pushes a world matrix since it renders outside the cam.Start3D2D.

@Nak2 Nak2 closed this as completed Jan 15, 2015
@Nak2 Nak2 reopened this Jan 15, 2015
@robotboy655 robotboy655 added the Bug The issue is confirmed to be a bug and not intentional behaviour. label Jan 15, 2015
@robotboy655
Copy link
Contributor

Well, then this is not a regression.

@Nak2
Copy link
Author

Nak2 commented Jan 15, 2015

Sorry, accidentally pressed the button when a window closed.
Short story:
I'm sure cam.PopModelMatrix pushes to a world matrix since it renders outside the target render.
HUDPaint - > even with cam.Start3D it renders on the screen as 2D
ENT:Draw / 3D-render - > renders at 0,0,0 and ignores the given scale

@Earu
Copy link

Earu commented Jan 4, 2020

This bug still exists on all current Gmod branches, it would be great if it was fixed. As stated above the model matrices pushed into a 3D context seem to completely mess up where things are gonna draw, their scales and angles. Is cam.Start3D2D pushing a matrix ?

You can reproduce this issue fairly easily, start a 2D context inside a 3D one using for instance cam.Start3D2D and push a Matrix object using cam.PushModelMatrix.

Alternatively if cam.Start3D2D indeed pushes a matrix it would be great if we could at least retrieve it from Lua.

@thegrb93
Copy link

thegrb93 commented Jan 4, 2020

Indeed cam.PushModelMatrix will replace the matrix used by cam.Start3D2D. It's bad enough cam.PushModelMatrix replaces matrices instead of multiplying, but not being able to cam.GetModelMatrix makes it impossible to do it ourselves.

@robotboy655
Copy link
Contributor

robotboy655 commented Jan 6, 2020

I can add cam.GetModelMatrix and with minor changes to the function above you can make it work:
yuy

Making changes to cam.PushModelMatrix can affect other addons in unexpected ways (and potentially the whole engine itself) so I probably won't be looking into that. Push/Pop matrix functions are direct bindings to in-engine stuff.

@robotboy655
Copy link
Contributor

robotboy655 commented Jan 6, 2020

Alternatively I could add an optional argument to PushModelMatrix that will get current matrix and push the multiplied result of current and input matrices instead.

Or I could do both.

Which would be preferred?

@Earu
Copy link

Earu commented Jan 6, 2020

Both would be incredibly helpful I'm sure!

@robotboy655
Copy link
Contributor

Added both, but it will be a short while before they are on Dev, build server's having a problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The issue is confirmed to be a bug and not intentional behaviour.
Projects
None yet
Development

No branches or pull requests

4 participants