Temporary rendering with colour.

Started by
9 comments, last by InfoGeek 9 years, 7 months ago

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.

Advertisement

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

My current game project Platform RPG

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


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.

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

Sean Middleditch – Game Systems Engineer – Join my team!

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


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.

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;
}

can anyone give me some pointers? i can't seem to figure it out and the stuff i find on the internet is unrelated(if i am searching for the right things).

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement