Jump to content

how 3d images?


Derpy

Recommended Posts

hey,how do you achieve something in mta like https://jgilronan.files.wordpress.com/2 ... isplay.jpg ?

(bottom left and right part of hud, its rectangle drawn on 2d screen but it's angle looks like its 3D)

how do you draw that type of 3d rectangles or 3d text?

DxDrawImage3D

DxDrawRectangle3D

That's for GTA world. I think he need to use shaders to achieve he's need.

Yes, a shader for it would be nice

do you know which shader can do this?

Link to comment

Example

i did create a new function for you.

Remember to use this .FX File.

3DPass.fx:

// 
// texPass.fx 
// Author: Blaawee 
// 
  
texture threeDimTex;     
  
technique tech 
{ 
    pass P0 
    { 
        Texture[0] = threeDimTex; 
    } 
} 
  

-- dxDrawImage3D( float posX, float posY, float width, float height, mixed image, float rotX, float rotY, float rotZ, float rotOfX, float rotOfY, float rotOfZ, int color, bool postGUI ) 
  
local texShader = dxCreateShader('3DPass.fx'); 
function dxDrawImage3D( posX, posY, width, height, image, rotX, rotY, rotZ, rotOfX, rotOfY, rotOfZ, color, postGUI ) 
  
    if not posX or not posY or not width or not height or not image then 
        return; 
    end 
     
    local rotX = rotX or 0; 
    local rotY = rotY or 0; 
    local rotZ = rotZ or 0; 
    local rotOfX = rotOfX or 0; 
    local rotOfY = rotOfY or 0; 
    local rotOfZ = rotOfZ or 0; 
    local color = color or tocolor( 255, 255, 255, 255 ); 
    local postGUI = postGUI or false; 
     
    local drawSurface = dxCreateRenderTarget( width, height, true ); -- Need to set the third arg to true to be created with an alpha channel.  
     
    if not drawSurface then 
        return; 
    end 
     
    if not texShader then 
        return; 
    end 
     
    dxSetShaderValue( texShader, 'threeDimTex', drawSurface ); 
    dxSetShaderTransform( texShader, rotX, rotY, rotZ, rotOfX, rotOfY, rotOfZ ); 
    dxSetRenderTarget( drawSurface ); 
    dxDrawImage( 0, 0, width, height, image, 0, 0, 0, color ); 
    dxSetRenderTarget( ); 
     
    dxDrawImage( posX, posY, width, height, texShader, 0, 0, 0, tocolor(255, 255, 255, 255), postGUI ); -- Draw the shader 
end 

Link to comment

hey man thanks i really appreciate that you've made a shader and whole function just for my topic :)

you're awesome.

but there's a problem :c

shader is loaded successfully, code is drawing something invisible for like 7 seconds then the render just stops itself somehow

i don't know if i'm doing anything wrong, i have tried using this test example

  
local imagee = "image.png"; 
  
-- ur code here 
  
--test 
function testing() 
dxDrawImage3D(50,50,500,500,imagee,10,10,25,15,20,30,tocolor(255,255,255,255),true); 
end; 
  
addEventHandler("onClientRender",root,testing); 

edit: sorry, my arguments made the image go somewhere i don't know, but still the render stops working after about 7 seconds..

Link to comment

Sorry buddy.. I was kinda busy. About the resource.. i did tried it and it's working normal nothing stopped or anything! i think it's about your calculation? Maybe you did it wrong! Try this instead :

local texShader = dxCreateShader('shared.fx'); 
local imagee = "image.png"; 
function dxDrawImage3D( posX, posY, width, height, image, rotX, rotY, rotZ, rotOfX, rotOfY, rotOfZ, color, postGUI ) 
      
    if not posX or not posY or not width or not height or not image then 
        return; 
    end 
        
    local rotX = rotX or 0; 
    local rotY = rotY or 0; 
    local rotZ = rotZ or 0; 
    local rotOfX = rotOfX or 0; 
    local rotOfY = rotOfY or 0; 
    local rotOfZ = rotOfZ or 0; 
    local color = color or tocolor( 255, 255, 255, 255 ); 
    local postGUI = postGUI or false; 
        
    local drawSurface = dxCreateRenderTarget( width, height, true ); -- Need to set the third arg to true to be created with an alpha channel. 
        
    if not drawSurface then 
        return; 
    end 
        
    if not texShader then 
        return; 
    end 
        
    dxSetShaderValue( texShader, 'threeDimTex', drawSurface ); 
         
    dxSetRenderTarget( drawSurface, true ); 
        dxDrawImage( 0, 0, width, height, image, 0, 0, 0, color ); 
    dxSetRenderTarget( ); 
         
    dxSetShaderTransform( texShader, rotX, rotY, rotZ, rotOfX, rotOfY, rotOfZ ); 
         
    dxDrawImage( posX, posY, width, height, texShader, 0, 0, 0, tocolor(255, 255, 255, 255), postGUI ); -- Draw the shader. 
         
    destroyElement( drawSurface ) 
end 
  
function testing1() 
    dxDrawImage3D( 250, 250, 500, 500, imagee, math.abs( getTickCount( )/20 ), 10, 30 )--,10,10,25,15,20,30,tocolor(255,255,255,255),true); 
end; 
  
addEventHandler("onClientRender",root,testing1); 

Link to comment

@ren i will check out the resource in couple of hours because currently i gotta go somewhere

@blaawee thanks man it works, i don't know why the render stopped working in my resource before.. you're brilliant

just 1 more question:

is it possible to use this shader and apply it on dxDrawText too or?

Link to comment

I've read a little about the function which you use for this shader (dxSetShaderTransform) and it says that it can apply 3d to images, but it doesn't say anything about text. Sorry, can you please give me an example how to do 3d text when you get free time?I'm not in a hurry with this, but would like to know how to do this 3d stuff in future :)

Link to comment

Test

Test

Test

Try this:

Remember To Use my .FX file.

function dxDrawText3D( text, left, top, right, bottom, color, scale, font, rotX, rotY, rotZ, rotOfX, rotOfY, rotOfZ, alignX, alignY, clip, wordBreak, postGUI, colorCoded ) 
     
    if not text or not left or not top then 
        return; 
    end 
     
    local right = right or 0; 
    local bottom = bottom or 0; 
    local color = color or tocolor( 255, 255, 255, 255 ); 
    local scale = scale or 1; 
    local font = font or "default"; 
    local rotX = rotX or 0; 
    local rotY = rotY or 0; 
    local rotZ = rotZ or 0; 
    local rotOfX = rotOfX or 0; 
    local rotOfY = rotOfY or 0; 
    local rotOfZ = rotOfZ or 0; 
    local alignX = alignX or "left"; 
    local alignY = alignY or "top"; 
    local clip = clip or false; 
    local wordBreak = wordBreak or false; 
    local postGUI = postGUI or false; 
    local colorCoded = colorCoded or true; 
     
    local textWidth = dxGetTextWidth( text, scale, font ); 
    local fontHeight = dxGetFontHeight( scale, font ); 
     
    local drawSurface = dxCreateRenderTarget( textWidth, fontHeight, true ); 
     
    if not drawSurface then 
        return; 
    end 
     
    if not texShader then 
        return; 
    end 
     
    dxSetShaderValue( texShader, 'threeDimTex', drawSurface ) 
     
  
    dxSetRenderTarget( drawSurface ) 
        dxDrawText( text, 0, 0, textWidth, fontHeight, color, scale, font, alignX, alignY, clip, wordBreak, postGUI, colorCoded, true ) 
    dxSetRenderTarget( ) 
     
    dxSetShaderTransform( texShader, rotX, rotY, rotZ, rotOfX, rotOfY, rotOfZ ); 
     
    dxDrawImage( left, top, textWidth, fontHeight, texShader, 0, 0, 0, tocolor( 255, 255, 255, 255 ), postGUI ); 
   
    destroyElement( drawSurface ); 
end 

Link to comment
  • 3 years later...

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...