Jump to content

2D Drawing to a Texture


Josh
 Share

Recommended Posts

Some people have asked me how to do this.  Here is an example:

local window=Window:Create("Draw to texture")

--Create the graphics context
context=Context:Create(window,0)
if context==nil then return end

--Create a world
world=World:Create()

local camera = Camera:Create()
camera:Move(0,0,-2)

local buffer = Buffer:Create(512,512,1,0)

local box = Model:Box()

local mtl = Material:Create()
mtl:SetTexture(buffer:GetColorTexture())
mtl:SetShader("Shaders/Model/diffuse.shader")
--local surf = box:GetSurface(0)
box:SetMaterial(mtl)
mtl:Release()

local font = Font:Load("Fonts/Arial.ttf",42)
context:SetFont(font)
font:Release()

world:SetAmbientLight(1,1,1)

while window:Closed()==false do
	
	box:Turn(0,0.2,0)
	Time:Update()
	world:Update()
	
	--Render to texture
	buffer:Enable()
	buffer:SetColor(0,0,1)
	buffer:Clear()
	buffer:SetColor(1,0,0)
	context:DrawRect(0,0,256,256)
	context:DrawRect(256,256,256,256)
	context:SetColor(1,1,1)
	context:SetBlendMode(Blend.Alpha)
	context:DrawText("Draw to texture! ;)",0,0,512,512,Text.Center+Text.VCenter)
	context:SetBlendMode(Blend.Solid)

	--Render world
	context:Enable()
	world:Render()
	context:Sync()
end

Image1.thumb.jpg.1093be36abf8b5b00c111af7d5523d7c.jpg

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

 

16 hours ago, jen said:

Useful for minimaps!

Never got round to mini maps yet so out of interest is the mechanism presented here the most obvious choice to go with or what are 1 or 2 other ways that might be considered?  

I imagine it depends on your game of course (as always) so I suppose I mean in most cases what methods might have been used?

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...