Jump to content

Getting troubles with drawText (invisible)


ScarPunk
 Share

Recommended Posts

Hello every one.

Today i am working on raycast, and a wanted to draw key value of an entity, but unfortunately it's doesn't draw text ;(

Here is a screenshot of the render:

draw_prob.thumb.PNG.57b21262020b616cab00c3cf2e1bb8d2.PNG

 

As you can see i am drawing first fps (who works)

then draw the line

and to finish draw keyvalue of the hit box (Fail)

 

Here is my code:

bool App::Loop()
{
	//quit ?
	if (window->Closed() or window->KeyHit(Key::Escape))return false;

	Red->Move();
	Green->Move();
	Blue->Move();
	world->Update();

	if (window->KeyDown(Key::Right))
	{
		camera->SetRotation(Vec3(camera->GetRotation().x, camera->GetRotation().y + 4, camera->GetRotation().z));
	}

	//REFRESH STUFF
	Time::Update();
	context->SetColor(0, 0, 0, 0);
	context->Clear();
	world->Render();


	//DRAW FPS
	context->SetBlendMode(Blend::Alpha);
	context->SetColor(255, 0, 0, 1);
	context->DrawText("FPS : " + String(Time::UPS()), 10, 20);

	//DRAW LINE
	context->SetBlendMode(Blend::Solid);
	context->SetColor((world->Pick(rayCastFirst, rayCastEnd, pickInfo) ? (rayCastColorOn) : (rayCastColorOff)));
	context->DrawLine(camera->Project(rayCastFirst).x, camera->Project(rayCastFirst).y, camera->Project(rayCastEnd).x, camera->Project(rayCastEnd).y);

	//set sphere to hit
	hitSphere->SetPosition((world->Pick(rayCastFirst, rayCastEnd, pickInfo,0,true)) ? (pickInfo.position) : (rayCastFirst) );
	
	//if hit DRAW KEY VALUE
	if (world->Pick(rayCastFirst, rayCastEnd, pickInfo, 0, true))
	{
		//fail
		context->SetColor(1, 1, 1, 1);
		context->SetBlendMode(Blend::Alpha);
		context->DrawText(pickInfo.entity->GetKeyValue("Color"), 20, 40);

	}


	context->Sync(true);

	return true;
}

 

Any reply will be appreciate ?

 

 

ART

CODE

SOUND

Link to comment
Share on other sites

1 hour ago, SpiderPig said:

Try printing some other text first, that will tell you if the world->pick has succeeded.  And maybe the entity doesn't have keyvalue named Color?

I put the DrawText(Keyvalue) before drawing the line, it's work but i don't know why it's doesn't works after drawing a line ?‍♂️

ART

CODE

SOUND

Link to comment
Share on other sites

Ah I see it now, your doing a pick again but this time the sphere is in the way. Try setting the spheres pick mode to '0' I think it is... or what would be better is to do the check once.

bool success = world->Pick(rayCastFirst, rayCastEnd, pickInfo, 0, true);

//Now use pickInfo

 

  • Like 1
Link to comment
Share on other sites

9 hours ago, SpiderPig said:

Ah I see it now, your doing a pick again but this time the sphere is in the way. Try setting the spheres pick mode to '0' I think it is... or what would be better is to do the check once.


bool success = world->Pick(rayCastFirst, rayCastEnd, pickInfo, 0, true);

//Now use pickInfo

 

 

9 hours ago, AggrorJorn said:

Try setting the same color as when drawing the FPS. You currently draw with an almost black color.

I tried both solutions without success but i find a fix !

I need to draw the keyvalue before drawing the line.

This is good but i don't know why it's work ;(

 

works_but_why.PNG

 

bool App::Loop()
{
	//quit ?
	if (window->Closed() or window->KeyHit(Key::Escape))return false;

	Red->Move();
	Green->Move();
	Blue->Move();
	world->Update();

	if (window->KeyDown(Key::Right))
	{
		camera->SetRotation(Vec3(camera->GetRotation().x, camera->GetRotation().y + 4, camera->GetRotation().z));
	}

	//REFRESH STUFF
	Time::Update();
	context->SetColor(0, 0, 0, 0);
	context->Clear();
	world->Render();


	//DRAW FPS
	context->SetBlendMode(Blend::Alpha);
	context->SetColor(255, 0, 0, 1);
	context->DrawText("FPS : " + String(Time::UPS()), 10, 20);

	//if hit DRAW KEY VALUE
	if (world->Pick(rayCastFirst, rayCastEnd, pickInfo, 0, true))
	{
		//fail

		//context->SetBlendMode(Blend::Alpha);
		context->SetColor(1, 1, 1, 1);
		context->DrawText(pickInfo.entity->GetKeyValue("Color"), 20, 40);

	}

	//DRAW LINE
	context->SetBlendMode(Blend::Solid);
	context->SetColor((world->Pick(rayCastFirst, rayCastEnd, pickInfo) ? (rayCastColorOn) : (rayCastColorOff)));
	context->DrawLine(camera->Project(rayCastFirst).x, camera->Project(rayCastFirst).y, camera->Project(rayCastEnd).x, camera->Project(rayCastEnd).y);

	//set sphere to hit
	hitSphere->SetPosition((world->Pick(rayCastFirst, rayCastEnd, pickInfo,0,true)) ? (pickInfo.position) : (rayCastFirst) );
	
	


	context->Sync(true);

	return true;
}

 

ART

CODE

SOUND

Link to comment
Share on other sites

Glad you got it working.  Your code at the moment is very inefficient.  You should structure it like this;

...	
world->Render();


//DRAW FPS
context->SetBlendMode(Blend::Alpha);
context->SetColor(1, 0, 0, 1);								//Use values 0.0 to 1.0
context->DrawText("FPS : " + String(Time::UPS()), 10, 20);

PickInfo pickInfo;
bool success = world->Pick(rayCastFirst, rayCastEnd, pickInfo);
if(success == true)
{
      //DRAW LINE
      Vec3 firstPos = camera->Project(rayCastFirst);
      Vec3 lastPos = camera->Project(rayCastEnd); 
      context->DrawLine(firstPos.x, firstPos.y, lastPos.x, lastPos.y);

      //DRAW KEY VALUE
      context->SetColor(1, 1, 1, 1);
      context->DrawText(pickInfo.entity->GetKeyValue("Color"), 20, 40);
}

//set sphere to hit
hitSphere->SetPosition((success == true) ? (pickInfo.position) : (rayCastFirst));

context->SetBlendMode(Blend::Solid);
context->Sync(true);

...

 

  • Thanks 2
Link to comment
Share on other sites

6 hours ago, SpiderPig said:

Glad you got it working.  Your code at the moment is very inefficient.  You should structure it like this;


...	
world->Render();


//DRAW FPS
context->SetBlendMode(Blend::Alpha);
context->SetColor(1, 0, 0, 1);								//Use values 0.0 to 1.0
context->DrawText("FPS : " + String(Time::UPS()), 10, 20);

PickInfo pickInfo;
bool success = world->Pick(rayCastFirst, rayCastEnd, pickInfo);
if(success == true)
{
      //DRAW LINE
      Vec3 firstPos = camera->Project(rayCastFirst);
      Vec3 lastPos = camera->Project(rayCastEnd); 
      context->DrawLine(firstPos.x, firstPos.y, lastPos.x, lastPos.y);

      //DRAW KEY VALUE
      context->SetColor(1, 1, 1, 1);
      context->DrawText(pickInfo.entity->GetKeyValue("Color"), 20, 40);
}

//set sphere to hit
hitSphere->SetPosition((success == true) ? (pickInfo.position) : (rayCastFirst));

context->SetBlendMode(Blend::Solid);
context->Sync(true);

...

 

It works thanks 

SpiderPig

  • Like 1

ART

CODE

SOUND

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