Sign in to follow this  

Temporary rendering with colour.

This topic is 1198 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey guys,

 

i need to render some text along other things. i want to be able to set a color value from c++ function and render text with itm then switch back. what is the best way of doing this?

 

 

 

 

i guess it will be something like creating one more constant buffer in effects file and in c++ and a structure with. maybe some voodo with a separate shader and some dynamic switching. in short i have no idea of the API good enough, that's why i am a beginner.

Edited by InfoGeek

Share this post


Link to post
Share on other sites

Create a texture with the text or render the text on-the-fly.  It has only an alpha value indicating where text is and is not.

The color of the text comes from a value passed to the shader (while the alpha value is retained from the text texture).

 

If you need something more, such as rendering text into some other image while only changing the color of the text, you will have to explain your needs better, but even that case is easy enough if you mark the text as a certain color and then replace that color in the shader with your currently desired text color.

 

 

L. Spiro

Share this post


Link to post
Share on other sites


Are you using any sort of graphics API or are you using Direct11 directly?

 

Direct11 directly.

 


Create a texture with the text or render the text on-the-fly.  It has only an alpha value indicating where text is and is not.
The color of the text comes from a value passed to the shader (while the alpha value is retained from the text texture).

 

i know...

 


If you need something more, such as rendering text into some other image while only changing the color of the text, you will have to explain your needs better, but even that case is easy enough if you mark the text as a certain color and then replace that color in the shader with your currently desired text color.

 

not sure what you mean by other image, all i want to render is to the same backbuffer/bound texture2D(typical tutorial way). i don't know how else to explain it, i need to draw a bunch of stuff, then use my text rendering function to render text of any colour i want, then render more stuff.

 

i already have a function to draw text and i can draw stuff. the problem is: i don't know the best way to render any colour text and then continue rendereing stuff normally.

 

sorry for my bad english.

Share this post


Link to post
Share on other sites

i already have a function to draw text and i can draw stuff. the problem is: i don't know the best way to render any color text and then continue rendereing stuff normally.

So, what exactly is wrong with the suggestion I (or SeanMiddleditch if you want individual characters to be different colors) already gave?



i don't know the best way to render any color text and then continue rendereing stuff normally.

The color of the text comes from a value passed to the shader (while the alpha value is retained from the text texture).

I don’t know how else I am supposed to answer.
Do you not know how to use multiple shaders?


#1: Activate text shader and alpha blending.
#2: Pass the color of the text to the shader.
#3: Shader outputs the color you passed + alpha from the texture containing the text (which you already know how to draw, apparently).
#4: Switch shader and continue rendering.


If your problem has not been solved into the dirt by now, you are going to have to get more specific on which part you do not understand how to do.


L. Spiro

Share this post


Link to post
Share on other sites


I usually just pass in an additional vertex attribute for color, which lets you change the color per character (useful for highlighting certain words in a phrase).

 

that was the first thing i thought. but i don't want the overhead from that for to change 100 chars to red i prefer using just 3 floats(rgb) instead of 100*4*3=1200 floats. 

Share this post


Link to post
Share on other sites

Do you not know how to use multiple shaders?

 
no sad.png . i followed a tutorial and i only have one file with two functions, one for pixel shader, second for vertex shader.
 
this is my shader file:
 

cbuffer CBPerObject
{
	float4x4 WVP;
};


Texture2D objTexture;
SamplerState objSamplerState;

struct VS_OUTPUT
{
	float4 position : SV_POSITION;
	float2 texturePosition : TEXPOS;
};

// Vertex Shader.
VS_OUTPUT VS(float4 inPos : POSITION, float2 inTexPos : TEXPOS)
{
	VS_OUTPUT output;
	output.position = mul(inPos, WVP);
	output.texturePosition = inTexPos;
	return output;
}


// Pixel Shader.
float4 PS(VS_OUTPUT input) : SV_TARGET
{
	float4 textureColor = objTexture.Sample(objSamplerState, input.texturePosition);
	return textureColor;
}

Share this post


Link to post
Share on other sites

Copy-paste those shader files and rename them.

Modify the new ones to do what you want.

Create a new shader using the 2 new files.

Activate shader 1 for the rendering you already do.

Activate shader 2 for the rendering you want to do with text.

 

 

L. Spiro

Share this post


Link to post
Share on other sites

thanks for the replies L. Spiro. if i have 4 shader files:

 

1 normal vertex

1 normal pixel

1 font pixel

1 font vertex(i probably don't even need this for changing solid colour of font right?)

 

what happens to global declarations? like the constant buffer, sample state object... how does it all come together?

Share this post


Link to post
Share on other sites

This topic is 1198 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

Sign in to follow this