• Using Textures On Derma
    10 replies, posted
I am using Draw.RoundedBoxEx and want to place an image over an area, i found this code: [CODE]local TexturedQuadStructure = { texture = surface.GetTextureID( '<path>' ), color = Color( 255, 255, 255, 255 ), x = 0, y = 0, w = 500, h = 500 } draw.TexturedQuad( TexturedQuadStructure )[/CODE] Now it works, but i want to add a custom image, i have already mate VTF and VMT files for the images i want to use, can anyone tell me where i put them? and what path i put in the <path> and is there anything else i have to do for this to work?
There is an example in the Garrysmod Wiki at the surface.GetTextureID. Example: A texture file is located at garrysmod/materials/custom/my_texture.vtf You would then use the following piece of code to retrieve it: [code]surface.GetTextureID("custom/my_texture")[/code] Make sure to rename the location of the texture in the .vtf file.
cheers, would i have to add them to FastDL?
If you plan on running the script on a server, then you have to FastDL.
Also i have 2 parts i need to place an image on, seporate images. [editline]19th May 2016[/editline] How can i use this code multiple times without it conflicting, i need to put the same code with a different image about 4 lines down. There's the Title Box and the Main Box, so far the code is only in the Main Box just below its code. When i put the same below the title box, it conflicts. [CODE] local Scroll = { texture = surface.GetTextureID( 'menu_textures/scroll' ), color = Color( 255, 255, 255, 255 ), x = 0, y = 0, w = 900, h = 900 } draw.TexturedQuad( Scroll )[/CODE] [CODE] local Wood= { texture = surface.GetTextureID( 'menu_textures/wood' ), color = Color( 255, 255, 255, 255 ), x = 0, y = 0, w = 900, h = 900 } draw.TexturedQuad( Wood)[/CODE]
By conflicting, do you then mean that they draw on top of eachother? Please explain.
um they either draw over each other or only one works and i get console error's.
I don't mean to butt in, but if I were in your situation, rather than using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/draw/TexturedQuad]draw.TexturedQuad[/url], I would use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/SetMaterial]surface.SetMaterial[/url] and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/DrawTexturedRect]surface.DrawTexturedRect[/url], I always find them easier and less buggy to use than anything to do with texture IDs
i'm using the draw because i'm not sure surface would work on this code. [QUOTE]I have a problem here, i have uploaded the following files. /garrysmod/materials/menu_textures/scroll.vmt /garrysmod/materials/menu_textures/scroll.vtf I added the following lines in the FastDL script. resource.AddSingleFile("materials/menu_textures/scroll.vmt") resource.AddSingleFile("materials/menu_textures/scroll.vtf") I have done a websync, and waited, i have restarted and in the menu i am using this code. -- Custom Background Image local Scroll = { texture = surface.GetTextureID( 'menu_textures/scroll' ), color = Color( 255, 255, 255, 255 ), x = 0, y = 0, w = 900, h = 900 } draw.TexturedQuad( Scroll ) But the texture is black and purple checker/missing.[/QUOTE]
[QUOTE=Shocks;50360591]i'm using the draw because i'm not sure surface would work on this code.[/QUOTE] [URL="https://github.com/garrynewman/garrysmod/blob/451b4ff5d1aea7b9b06a8024ef706c248a79647e/garrysmod/lua/includes/modules/draw.lua#L287-L295"]But the draw library uses surface library code internally[/URL]? I guess it wouldn't make a difference what you used, but I'm just saying [editline]20th May 2016[/editline] Really, the only difference between what I'm saying and what you're doing is that I was suggesting to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/SetMaterial]surface.SetMaterial[/url] instead of setting the texture [editline]20th May 2016[/editline] Try this: [CODE] local mat = Material( 'menu_textures/scroll' ) surface.SetMaterial( mat ) surface.SetDrawColor( 255, 255, 255, 255 ) surface.DrawTexturedRect( 0, 0, 900, 900 ) [/CODE] But make sure to not create the material variable inside any drawing hooks, since that's expensive
This is the code for the initial menu background [CODE] draw.RoundedBoxEx( 4, 6, 0, self:GetWide() - 12, self:GetTall() - 1, Color( 241, 217, 153, 255 ), false, false, true, true ) -- Menu Background [/CODE] i need to set the material/texture of that. will your code work on that, i've tried it and nothing changed, it does with [CODE]local Scroll = { texture = surface.GetTextureID( 'menu_textures/scroll' ), color = Color( 255, 255, 255, 255 ), x = 0, y = 0, w = 900, h = 900 } draw.TexturedQuad( Scroll )[/CODE] But the texture is checker, but when i use other materials from in game they flicker depending on what direction your facing. its odd. [editline]21st May 2016[/editline] Ok your code works but the texture is still checker, i have put it in the right place and i have websynced and put it in the fast download and restarted. im so confused to why this won't work. This is the VMT file for the material. [CODE]"UnlitGeneric" { "$basetexture" "menu_textures/scroll" }[/CODE]
Sorry, you need to Log In to post a reply to this thread.