Text disappeared when a gui is rendered to texture (SOLVED)


#1

Hello,
I have a gui which uses same materials with default one except having a “rtt” tag. I rendered this gui to texture and text disappears once I re-render the gui.
Depth things were suspicious so I cleared render target and rendered only fonts, which makes same result fonts disappear from second render.

	render.set_depth_mask(true)
	render.set_stencil_mask(0xff)
	render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0})

	render.set_depth_mask(false)
	render.disable_state(render.STATE_DEPTH_TEST)
	render.disable_state(render.STATE_STENCIL_TEST)
	render.enable_state(render.STATE_BLEND)
	render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)
	render.disable_state(render.STATE_CULL_FACE)
		
	if dirty == nil then

		dirty = 0

		render.enable_render_target(self.cardRT)
		render.set_viewport(0, 0, 1024, 1024)
		render.set_view(vmath.matrix4_orthographic(0, 1023, 0, 1023, 0, 1))

		render.enable_state(render.STATE_STENCIL_TEST)
		render.draw(self.cardRTT_pred)
		render.disable_state(render.STATE_STENCIL_TEST)
		
		render.disable_render_target(self.cardRT)

	else

		dirty = dirty + 1

		if dirty >= 30 then
			dirty = nil
		end
		
	end

#2

Does the font material for the text also have the “rtt”-tag? By default text is rendered after gui with a separate predicate, have a look at the default render script for an example of this.


#3

Where and how do you use the render target as texture?


#4

Thanks for your answers.

to Johann_Beck-Noren
Definitely I added “rtt” tag to fonts. I tried to use same predicate with gui and the result was same.

to sicher
Here is the full source of render script.




function init(self)

	local color_params = {	format = render.FORMAT_RGBA,
							width = 1024,
							height = 1024,
							min_filter = render.FILTER_LINEAR,
							mag_filter = render.FILTER_LINEAR,
							u_wrap = render.WRAP_CLAMP_TO_EDGE,
							v_wrap = render.WRAP_CLAMP_TO_EDGE }

	self.cardRT = render.render_target("cardRT", {[render.BUFFER_COLOR_BIT] = color_params })	
	
	self.tile_pred = render.predicate({"tile"})
	self.guipers_pred = render.predicate({"gui_pers"})
	self.guiortho_pred = render.predicate({"gui_ortho"})
	self.text_pred = render.predicate({"text"})
	self.particle_pred = render.predicate({"particle"})
	self.model_pred = render.predicate({"model"})
	self.cardRTT_pred = render.predicate({"card_rtt"})
	self.cardModel_pred = render.predicate({"card_model"})
		
	self.clear_color = vmath.vector4(0, 0, 0, 0)
	self.clear_color.x = sys.get_config("render.clear_color_red", 0)
	self.clear_color.y = sys.get_config("render.clear_color_green", 0)
	self.clear_color.z = sys.get_config("render.clear_color_blue", 0)
	self.clear_color.w = sys.get_config("render.clear_color_alpha", 0)


	local w = render.get_window_width() * 0.5
	local h = render.get_window_height() * 0.5
	local eye = vmath.vector3(w, h-250, 1000)
	local look_at = vmath.vector3(w, h-50, 0)
	local up = vmath.vector3(0, 1.0, 0)

	self.view = vmath.matrix4_look_at(eye, look_at, up)	

end

local dirty

function update(self)
	
	render.set_depth_mask(true)
	render.set_stencil_mask(0xff)
	render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0})

	render.set_depth_mask(false)
	render.disable_state(render.STATE_DEPTH_TEST)
	render.disable_state(render.STATE_STENCIL_TEST)
	render.enable_state(render.STATE_BLEND)
	render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)
	render.disable_state(render.STATE_CULL_FACE)
		
	if dirty == nil then

		dirty = 0

		render.enable_render_target(self.cardRT)
		render.set_viewport(0, 0, 1024, 1024)
		render.set_view(vmath.matrix4_orthographic(0, 1023, 0, 1023, 0, 1))

		render.enable_state(render.STATE_STENCIL_TEST)
		render.draw(self.cardRTT_pred)
		render.disable_state(render.STATE_STENCIL_TEST)
		
		render.disable_render_target(self.cardRT)

	else

		dirty = dirty + 1

		if dirty >= 30 then
			dirty = nil
		end
		
	end
		
	-- Perspective projection

	render.set_viewport(0, 0, render.get_window_width(), render.get_window_height())
	render.set_view(self.view)
	render.set_projection(vmath.matrix4_perspective(1, 0.6, 0.1, 2000))
	
	render.draw(self.guipers_pred)

	render.draw(self.tile_pred)
	render.draw(self.model_pred)
	render.draw(self.particle_pred)


	render.enable_texture(0, self.cardRT, render.BUFFER_COLOR_BIT)
	render.draw(self.cardModel_pred)
	render.disable_texture(0, self.cardRT)
	
	render.draw_debug3d()


	-- render GUIOrtho
	-- Orthogonal projection
	render.set_view(vmath.matrix4())
	render.set_projection(vmath.matrix4_orthographic(0, render.get_window_width(), 0, render.get_window_height(), -1, 1))
		
	render.enable_state(render.STATE_STENCIL_TEST)
	render.draw(self.guiortho_pred)
	render.draw(self.text_pred)
	render.disable_state(render.STATE_STENCIL_TEST)

	render.draw_debug2d()	
end

function on_message(self, message_id, message)
	if message_id == hash("clear_color") then
		self.clear_color = message.color
	elseif message_id == hash("set_view_projection") then
		self.view = message.view
	elseif message_id == hash("render_card_texture") then


	end

end



#5

I got the answer. I forgot reset projection matrix for RTT and somehow gui was drawn correctly whereas font has disappeared. Thank you.