• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Render Text in 3D

C

Charzendat

Guest
Hi all. I've been using Game Maker for a long time but am only now just getting into the 3D aspects of it. Everything is going alright but I am having difficulties rendering text in the 3D environment. I can draw things to a HUD but if I have an object and I want some text to float above it, what should I do? I have checked many a tutorial and none seem to answer this question so if anyone can advise me it would be appreciated.
 

Fredrik

Member
I might have a solution, but I'm not 100% sure if it'll work or not, and I'm pretty sure there's someone having a better idea.

In the Draw Event for your object try adding this script:

Code:
var tex;
tex = sprite_get_texture(spr_ironsword,0);
d3d_draw_wall(x-global.itmsize1*global.camsin,y-global.itmsize1*global.camcos,z2-global.itmsize2,x+global.itmsize1*global.camsin,y+global.itmsize1*global.camcos,z1,tex,1,1);
This one will create a wall always facing towards your camera/view, with the texture of the wall being the local variable "tex", which in this example is set to be sprite_get_texture(sprite,subimage);, what you'll have to do (if it works) is to change the "sprite_get_texture" function to a draw_text function, perhaps like this:

Code:
tex = draw_text(x,y,text);
You'll also have to preset the z1 and z2 variable seen in the script, as they decide the bottom height and the top height of the wall.

I should also mention that this script is copied from one of my projects, so variables like "global.itemsize2" is not realive to your project, and variables like camsin, camcos and such is also relative to my 3d projection. A smiliar script which is much cleaner can be found in Yoyogames own 3D tutorial.
 
C

Charzendat

Guest


Thank you for the tip Fredrik but your method didn't work. I have now got it working though.

Code:
draw_set_halign(fa_center)
draw_set_valign(fa_middle)
tex=sprite_get_texture(sprite_index,image_index)

d3d_transform_set_identity();
d3d_transform_add_rotation_x(90)
d3d_transform_add_translation(x,y,z)
draw_text(0,0,"HELLO")
d3d_transform_set_identity();

d3d_draw_wall(x-sprite_width/4,y,z+sprite_height/2,x+sprite_width/4,y,z,tex,1,1)
So when I was just drawing the text at the X,Y position of my object, it would draw it flat on the ground. I figured out how to translate it upwards, but it was still flat so not really readable. Rotating it wasn't really working because when you rotate in 3D it does it around 0,0,0. I then figured to draw the text at 0,0,0 and then transform it to the position needed.
 
Top