I want to show text in screen independently while using 3D camera

import java.awt.AWTException;
import java.awt.Robot;

public class Player{
  public float x;
  public float y;
  public float z;
  public float vz;
  public float theta;
  public float phi;
  public float speed;
}

boolean isUp,isDown,isRight,isLeft,isJump;
int Pspeed = 5;
Robot robby;  
PGraphics pg;

int w=1920,h=1080;
Player P=new Player();
void setup(){
  fullScreen(P3D);
  P.x=0;
  P.y=0;
  P.z=100;
  P.theta=P.phi=0;
  P.speed = 5;
  try
  {
    robby = new Robot();
  }
  catch (AWTException e)
  {
    println("Robot class not supported by your system!");
    exit();
  }
  robby.mouseMove(w/2,h/2);
  pg = createGraphics(w, h);
}

void drawSphere(float x,float y,float z,float r){
  pushMatrix();
    translate(x,y,z);
    sphere(r);
  popMatrix();
}


void keyPressed() {
  setMove(keyCode, true);
}
 
void keyReleased() {
  setMove(keyCode, false);
}

boolean setMove(int k, boolean b) {
  switch (k) {
  case 'W':
  case UP:
    return isUp = b;
 
  case 'S':
  case DOWN:
    return isDown = b;
 
  case 'A':
  case LEFT:
    return isLeft = b;
 
  case 'D':
  case RIGHT:
    return isRight = b;
    
  case ' ':
    return isJump = b;
 
  default:
    return b;
  }
}

void moveP(){
  if(isUp){
    P.x+=P.speed*cos(P.theta);
    P.y+=P.speed*sin(P.theta);
  }
  if(isDown){
    P.x-=P.speed*cos(P.theta);
    P.y-=P.speed*sin(P.theta);
  }
  if(isLeft){
    P.x+=P.speed*sin(P.theta);
    P.y-=P.speed*cos(P.theta);
  }
  if(isRight){
    P.x-=P.speed*sin(P.theta);
    P.y+=P.speed*cos(P.theta);
  }
  if(isJump){
    if(P.z-100<=5)
      P.vz=10;
  }
  P.z+=P.vz;
  if(P.z-100>0)
    P.vz-=0.5;
  P.z=max(P.z,100);
}


void draw(){
  noCursor();
  background(255/2);
//THIS IS THE CODE//
  hint(DISABLE_DEPTH_TEST);
  pushMatrix();
  resetMatrix();
  fill(255);
  camera();
  textSize(50);
  text("Quarks was here", 700,700);
  popMatrix();
  hint(ENABLE_DEPTH_TEST);
//THIS IS THE CODE//
  rectMode(CENTER);
  fill(128,64,0);
  rect(0,0,1000,1000);
  lights();
  fill(0,0,255);
  drawSphere(0,0,300,100);
  fill(0,255,0);
  drawSphere(0,300,0,100);
  fill(255,0,0);
  drawSphere(300,0,0,100);
  fill(255,255,0);
  drawSphere(0,0,-300,100);
  fill(255,0,255);
  drawSphere(0,-300,0,100);
  fill(0,255,255);
  drawSphere(-300,0,0,100);
  P.theta+=-(w/2-mouseX+0.0)*3/w;
  P.phi+=-(h/2-mouseY+0.0)/h;
  P.phi=constrain(P.phi,-PI/2,PI/2);
  robby.mouseMove(w/2,h/2);
  moveP();
  camera(P.x,P.y,P.z,
  P.x+cos(P.phi)*cos(P.theta),P.y+cos(P.phi)*sin(P.theta),P.z-sin(P.phi),
  cos(P.phi+90)*cos(P.theta),cos(P.phi+90)*sin(P.theta),-sin(P.phi+90));
//THIS IS THE CODE//
  hint(DISABLE_DEPTH_TEST);
  pushMatrix();
  resetMatrix();
  fill(255);
  camera();
  textSize(50);
  text("Quarks was here", 150,150);
  popMatrix();
  hint(ENABLE_DEPTH_TEST);
//THIS IS THE CODE//
}

This is my code, and I wanted to write a independent text on the screen from the 3d images I’m showing. You can see the codes I’ve tried at draw function. The code written above the text is obscured by the 3d objects, and the code written below changes transparency while I move my mouse.
Why does this happen? And how can I show text at my screen, without any of these problems?

2 Likes

See number 9

2 Likes

…and welcome to the forum!

Great to have you here!

2 Likes

Great thanks to you. So it was because I haven’t turned off the lights… I am really new to processing(It’s been only two weeks since I’ve been taught this at school and I’m been told to make a fps game ;-; ) and it’s really kind of you to answer this so fast! Thanks again!

2 Likes