Jump to content

object_preview How to draw effect on DX drawing ?!


darhal

Recommended Posts

Hello All;

I m using object_preview resources (by Ren) to draw ped preview but I need the effect to be drawn before the dx drawing but I cant figure it out

Ren told me to do some changes on c_main it dont work so here is my code :

c_main.lua from line 323 :

-- onClientHUDRender 
addEventHandler( "onClientRender", root, function() 
isMRTUsed = false 
if not isMRTShaderSupported or (#refOPTable == 0) then  
return  
end 
for index, this in ipairs( refOPTable ) do 
-- Draw secondary render target 
if refOPTable[index] then 
if refOPTable[index].isSecondRT then 
isMRTUsed = true 
end 
if refOPTable[index].enabled then 
local instance = this.instance 
if instance then 
instance:drawRenderTarget() 
end 
end 
end 
end 
if (isMRTUsed == false) and glRenderTarget then 
destroyElement( glRenderTarget ) 
glRenderTarget = nil 
outputDebugString('objPrev : no MRT objects visible - destroyed RT') 
end 
end, true, "high+10") 

My resource thet draw the DX :

addEventHandler("onClientRender", root, drawInventory) 
addEventHandler("onClientRender", root, drawViewingItems) 
inventoryShown = true 
removeEventHandler("onClientRender", root, drawUseBar) 
showCursor(true) 
local x, y, z = getElementRotation(localPlayer) 
local rx, ry, rz = getElementRotation(localPlayer) 
ped = createPed(getElementModel(localPlayer),x ,y ,z, rx, ry, rz) 
myObject = exports.object_preview:createObjectPreview(ped,0,0,180, 95, 136, 170, 307, false, true, false) 

Thanks in advance !

Link to comment
  • Moderators

Well, then I am sorry too. But that is how addEventHandlers work.

You sure you aren't drawing anything over the GUI? Because if you set that optional argument to true, the dx will be drawing after the gui's have been drawn.

Link to comment
  • Moderators
You sure you aren't drawing anything over the GUI? Because if you set that optional argument to true, the dx will be drawing after the gui's have been drawn.

dxDrawRectangle(35, 24, 744, 551, tocolor(0, 0, 0, 236), [color=#FF0000]true[/color]) 

syntax

dxDrawRectangle ( float startX, float startY, float width, float height [, int color = white, [color=#FF0000]bool postGUI = false[/color], bool subPixelPositioning = false ] ) 

dxDrawRectangle(35, 24, 744, 551, tocolor(0, 0, 0, 236), [color=#00BF00]false[/color]) 

Link to comment

Well thanks for replying but nothing happen

Here is my code that draw inventory :

  
   function drawInventory() 
        dxDrawLine(35 - 1, 24 - 1, 35 - 1, 575, tocolor(0, 0, 0, 220), 1, false) 
        dxDrawLine(779, 24 - 1, 35 - 1, 24 - 1, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawLine(35 - 1, 575, 779, 575, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawLine(779, 575, 779, 24 - 1, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawRectangle(35, 24, 744, 551, tocolor(0, 0, 0, 236), false) 
        dxDrawRectangle(35, 24, 744, 46, tocolor(32, 32, 32, 255), false) 
        dxDrawRectangle(333, 202, 408, 324, tocolor(18, 18, 18, 143), false) 
        dxDrawText("CUP - Inventory", 33 + 1, 24 + 1, 779 + 1, 70 + 1, tocolor(0, 0, 0, 255), 3.00, "default-bold", "center", "center", true, false, false, true, false) 
        dxDrawText("CUP - Inventory", 33, 24, 779, 70, tocolor(255, 255, 255, 255), 3.00, "default-bold", "center", "center", true, false, false, true, false) 
        dxDrawRectangle(47, 92, 260, 449, tocolor(18, 18, 18, 143), false) 
        outLineRectangle(47, 92, 260, 449) 
        dxDrawRectangle(50, 92, 257, 35, tocolor(25, 25, 25, 243), false) 
        outLineRectangle(50, 92, 257, 35) 
        dxDrawText("Player Preview", 49 + 1, 93 + 1, 307 + 1, 127 + 1, tocolor(0, 0, 0, 255), 2.00, "default-bold", "center", "center", false, false, false, true, false) 
        dxDrawText("Player Preview", 49, 93, 307, 127, tocolor(255, 255, 255, 255), 2.00, "default-bold", "center", "center", false, false, false, true, false) 
        dxDrawRectangle(322, 93, 457, 446, tocolor(56, 56, 56, 72), false) 
        outLineRectangle(322, 93, 457, 446) 
        dxDrawRectangle(321, 93, 453, 34, tocolor(34, 34, 34, 209), false) 
        outLineRectangle(321, 93, 453, 34) 
        dxDrawText("Items", 321, 93, 774, 127, tocolor(255, 255, 255, 255), 2.00, "default-bold", "center", "center", false, false, false, true, false) 
        dxDrawRectangle(323, 136, 451, 56, tocolor(32, 32, 32, 222), false) 
        for i, v in pairs(groupCord) do 
            dxDrawRectangle(v.x, v.y, v.w, v.h, v.color, false) 
            outLineRectangle(v.x, v.y, v.w, v.h) 
            dxDrawImage(v.x, v.y, v.w, v.h, v.path, 0, 0, 0, tocolor(255, 255, 255, 255), false) 
        end 
        dxDrawLine(747 - 1, 198 - 1, 747 - 1, 525, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawLine(774, 198 - 1, 747 - 1, 198 - 1, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawLine(747 - 1, 525, 774, 525, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawLine(774, 525, 774, 198 - 1, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawRectangle(747, 198, 27, 327, tocolor(4, 4, 4, 143), false) 
        dxDrawRectangle(747, 337, 27, 188, tocolor(85, 151, 7, 242), false) 
         
        for i, v in pairs(itemsCord) do 
            dxDrawRectangle(v.x, v.y, v.h, v.w, v.color, false) 
            outLineRectangle(v.x, v.y, v.h, v.w) 
        end 
         
        for i, v in pairs(fastCord) do 
            dxDrawRectangle(v.x, v.y, v.h, v.w, v.color, false) 
            outLineRectangle(v.x, v.y, v.h, v.w) 
        end 
        dxDrawLine(81 - 1, 474 - 1, 81 - 1, 504, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawLine(275, 474 - 1, 81 - 1, 474 - 1, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawLine(81 - 1, 504, 275, 504, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawLine(275, 504, 275, 474 - 1, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawRectangle(81, 474, 194, 30, openCraftColor, false) 
        dxDrawText("Open Crafting Table", 81 - 1, 473 - 1, 275 - 1, 504 - 1, tocolor(0, 0, 0, 255), 1.20, "default-bold", "center", "center", false, false, false, true, false) 
        dxDrawText("Open Crafting Table", 81 + 1, 473 - 1, 275 + 1, 504 - 1, tocolor(0, 0, 0, 255), 1.20, "default-bold", "center", "center", false, false, false, true, false) 
        dxDrawText("Open Crafting Table", 81 - 1, 473 + 1, 275 - 1, 504 + 1, tocolor(0, 0, 0, 255), 1.20, "default-bold", "center", "center", false, false, false, true, false) 
        dxDrawText("Open Crafting Table", 81 + 1, 473 + 1, 275 + 1, 504 + 1, tocolor(0, 0, 0, 255), 1.20, "default-bold", "center", "center", false, false, false, true, false) 
        dxDrawText("Open Crafting Table", 81, 473, 275, 504, tocolor(255, 255, 255, 255), 1.20, "default-bold", "center", "center", false, false, false, true, false) 
        --exports.object_preview:setProjection(myObject, 95, 136, 170, 307) 
        if currentDragItem and not isCraftingOpen  then 
            dxDrawImage(cX-20, cY-20, 41, 41, currentDragItem.path, 0, 0, 0, tocolor(255, 255, 255, 200), false) 
        end 
    end 
     
function showInventory() 
    if cantCloseInventory then return end 
    if not inventoryShown then 
        if groupItemsSave[lastRealGroup] then 
            currentViewingItems = groupItemsSave[lastRealGroup] 
        else 
            currentViewingItems = {} 
        end 
        addEventHandler("onClientRender", root, drawInventory) 
        addEventHandler("onClientRender", root, drawViewingItems) 
        inventoryShown = true 
        removeEventHandler("onClientRender", root, drawUseBar) 
        showCursor(true) 
        local x, y, z = getElementRotation(localPlayer) 
        local rx, ry, rz = getElementRotation(localPlayer) 
        ped = createPed(getElementModel(localPlayer),x ,y ,z, rx, ry, rz) 
        myObject = exports.object_preview:createObjectPreview(ped,0,0,180, 95, 136, 170, 307, false, true, false) 
    elseif inventoryShown then 
        removeEventHandler("onClientRender", root, drawInventory) 
        removeEventHandler("onClientRender", root, drawViewingItems) 
        inventoryShown = false 
        addEventHandler("onClientRender", root, drawUseBar) 
        showCursor(false) 
        destroyElement(ped) 
        exports.object_preview:destroyObjectPreview(myObject) 
        if isCraftingOpen then 
            removeEventHandler("onClientRender", root, drawCrafting) 
            isCraftingOpen = false 
            cCraftProgress = nil 
            cantCloseInventory = false 
        end 
    end 
end 
bindKey("i", "down", showInventory) 
  

Link to comment
  • Moderators

These are the two factors that can change the render ordering between two onClientRender handlers.

There is only 1 thing left, both are using the same event >"onClientRender"<?

If they are, then you are mistaking somewhere else.

Link to comment
  • Moderators

I don't know exactly what (Multiple Render Targets) are, but afaik that has nothing to do with rendering 2D MTA(dx functions) layers over each other.

But if you have your visuals, it has to do with your or ren's code.

Link to comment

test :#

   function drawInventory() 
        dxDrawLine(35 - 1, 24 - 1, 35 - 1, 575, tocolor(0, 0, 0, 220), 1, false) 
        dxDrawLine(779, 24 - 1, 35 - 1, 24 - 1, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawLine(35 - 1, 575, 779, 575, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawLine(779, 575, 779, 24 - 1, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawRectangle(35, 24, 744, 46, tocolor(32, 32, 32, 255), false) 
        dxDrawRectangle(333, 202, 408, 324, tocolor(18, 18, 18, 143), false) 
        dxDrawText("CUP - Inventory", 33 + 1, 24 + 1, 779 + 1, 70 + 1, tocolor(0, 0, 0, 255), 3.00, "default-bold", "center", "center", true, false, false, true, false) 
        dxDrawText("CUP - Inventory", 33, 24, 779, 70, tocolor(255, 255, 255, 255), 3.00, "default-bold", "center", "center", true, false, false, true, false) 
        dxDrawRectangle(47, 92, 260, 449, tocolor(18, 18, 18, 143), false) 
        outLineRectangle(47, 92, 260, 449) 
        dxDrawRectangle(50, 92, 257, 35, tocolor(25, 25, 25, 243), false) 
        outLineRectangle(50, 92, 257, 35) 
        dxDrawText("Player Preview", 49 + 1, 93 + 1, 307 + 1, 127 + 1, tocolor(0, 0, 0, 255), 2.00, "default-bold", "center", "center", false, false, false, true, false) 
        dxDrawText("Player Preview", 49, 93, 307, 127, tocolor(255, 255, 255, 255), 2.00, "default-bold", "center", "center", false, false, false, true, false) 
        dxDrawRectangle(322, 93, 457, 446, tocolor(56, 56, 56, 72), false) 
        outLineRectangle(322, 93, 457, 446) 
        dxDrawRectangle(321, 93, 453, 34, tocolor(34, 34, 34, 209), false) 
        outLineRectangle(321, 93, 453, 34) 
        dxDrawText("Items", 321, 93, 774, 127, tocolor(255, 255, 255, 255), 2.00, "default-bold", "center", "center", false, false, false, true, false) 
        dxDrawRectangle(323, 136, 451, 56, tocolor(32, 32, 32, 222), false) 
        dxDrawRectangle(35, 24, 744, 551, tocolor(0, 0, 0, 236), false) 
        for i, v in pairs(groupCord) do 
            dxDrawRectangle(v.x, v.y, v.w, v.h, v.color, false) 
            outLineRectangle(v.x, v.y, v.w, v.h) 
            dxDrawImage(v.x, v.y, v.w, v.h, v.path, 0, 0, 0, tocolor(255, 255, 255, 255), false) 
        end 
        dxDrawLine(747 - 1, 198 - 1, 747 - 1, 525, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawLine(774, 198 - 1, 747 - 1, 198 - 1, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawLine(747 - 1, 525, 774, 525, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawLine(774, 525, 774, 198 - 1, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawRectangle(747, 198, 27, 327, tocolor(4, 4, 4, 143), false) 
        dxDrawRectangle(747, 337, 27, 188, tocolor(85, 151, 7, 242), false) 
        
        for i, v in pairs(itemsCord) do 
            dxDrawRectangle(v.x, v.y, v.h, v.w, v.color, false) 
            outLineRectangle(v.x, v.y, v.h, v.w) 
        end 
        
        for i, v in pairs(fastCord) do 
            dxDrawRectangle(v.x, v.y, v.h, v.w, v.color, false) 
            outLineRectangle(v.x, v.y, v.h, v.w) 
        end 
        dxDrawLine(81 - 1, 474 - 1, 81 - 1, 504, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawLine(275, 474 - 1, 81 - 1, 474 - 1, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawLine(81 - 1, 504, 275, 504, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawLine(275, 504, 275, 474 - 1, tocolor(0, 0, 0, 255), 1, false) 
        dxDrawRectangle(81, 474, 194, 30, openCraftColor, false) 
        dxDrawText("Open Crafting Table", 81 - 1, 473 - 1, 275 - 1, 504 - 1, tocolor(0, 0, 0, 255), 1.20, "default-bold", "center", "center", false, false, false, true, false) 
        dxDrawText("Open Crafting Table", 81 + 1, 473 - 1, 275 + 1, 504 - 1, tocolor(0, 0, 0, 255), 1.20, "default-bold", "center", "center", false, false, false, true, false) 
        dxDrawText("Open Crafting Table", 81 - 1, 473 + 1, 275 - 1, 504 + 1, tocolor(0, 0, 0, 255), 1.20, "default-bold", "center", "center", false, false, false, true, false) 
        dxDrawText("Open Crafting Table", 81 + 1, 473 + 1, 275 + 1, 504 + 1, tocolor(0, 0, 0, 255), 1.20, "default-bold", "center", "center", false, false, false, true, false) 
        dxDrawText("Open Crafting Table", 81, 473, 275, 504, tocolor(255, 255, 255, 255), 1.20, "default-bold", "center", "center", false, false, false, true, false) 
        --exports.object_preview:setProjection(myObject, 95, 136, 170, 307) 
        if currentDragItem and not isCraftingOpen  then 
            dxDrawImage(cX-20, cY-20, 41, 41, currentDragItem.path, 0, 0, 0, tocolor(255, 255, 255, 200), false) 
        end 
    end 

Link to comment

In your resources line 9 you have createObjectPreview function. I noticed that you create a non Multiple Render Target variant ( the last variable is set to 'false'). The visible vehicle is rendered in world space (before MTA stuff), it is not rendered in a separate render target. Change the last flag to true and you'll get MRT effect. You'd cartainly notice that your graphics card doesn't support MRT in shader - you'd be notified in chatbox and debug.

Link to comment
Is it possible to prevent the object_preview from "flickering" as soon as the object preview is created or destroyed? I could offer a video showing this and other issues.

I also noticed that. I don't really know what seems to be the reason of that - is the effect is applied later, or some variable is not set at startup. Please send PM with link to the video.

thank you now you made things clear but if my graphics card dont support MRT it will not work ? (Wwill not be drawn before DX ?) thx in advance

When you start the objectPreview resource - if your GFX doesn't support MRT then you will be noted in chatbox - objPrev: 'MRT in shaders not supported!' In this case If you create preview of an object with MRT flag set to true - the object will not be rendered and the function will return false.

Link to comment
Here is the video for all.

...

I assume that it happens only for an MRT variant. For some graphics cards the alpha of the world object seems to be too low - it needs to exceed a certain value. I increased it. Download the latest version and tell me if it changes anything.

Edited by Guest
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...