3D [3D] trying to draw text on a d3d_wall, maybe surface issue?

D

Dengar

Guest
im using gm studio1.4 and im trying to draw text on a wall in 3d. I'm using billboarding so its a 2d sprite that faces the player at all times, everything works except the text part.
the method im trying is to create a surface, then draw sprite and text to surface, then use surface as texture for the d3d_wall. but when I run the code below nothing is drawn.
ive not included the part that calculates the x1,x2,y1,y2 variables for drawing the wall as its not part of the problem.

I don't have a lot of experience with surfaces so I assume I'm just declaring things wrong, id be grateful for any help. also if you have a better way then please share.

Code:
su=surface_create(32, 32);
surface_set_target(su);
draw_clear_alpha(c_black,0.0);
draw_sprite(sprite4,spritedir,0,0);
draw_set_font(font0);
draw_text(0,0,"testing");
draw_set_font(-1);


d3d_draw_wall(x1,y1,16,x2,y2,0,surface_get_texture(su),1,1);
surface_reset_target();
surface_free(su);
 
Hi, before I say anthying else, you're not creating a new surface and freeing it every single frame, are you? That's not ideal.

Now, when you say "nothing is drawn", what do you mean exactly? Do you mean that the wall is totally invisible? Do you mean it is completely black? Do you mean you can see the sprite but not the font?

I'm taking a sort of stab in the dark here and say its because d3d_start is on, which converts from right to left handed coordinate system (resulting in y appearing reversed).
 
D

Dengar

Guest
Hi, before I say anthying else, you're not creating a new surface and freeing it every single frame, are you? That's not ideal.

Now, when you say "nothing is drawn", what do you mean exactly? Do you mean that the wall is totally invisible? Do you mean it is completely black? Do you mean you can see the sprite but not the font?
just until I get it working yes, im creating and destroying the surface every step. this is just for testing until I get it working.

when I say nothing is drawn I mean the room is drawn and camera system works, but the wall isn't being drawn at all(invisible) also I have another d3d_wall that vanishes too yet the d3d blocks still draw, its weird.

how should it be setup to create surface, draw sprite, draw text, and use surface as texture?
 
Oh wait a second, you are doing surface_reset_target in the wrong place. Do it before drawing the wall. I still think your wall is going to look wrong because of the coordinate system. Bet we'll see.
 
D

Dengar

Guest
Oh wait a second, you are doing surface_reset_target in the wrong place. Do it before drawing the wall. I still think your wall is going to look wrong because of the coordinate system. Bet we'll see.
still draws invisible.

not sure what ur saying about the coordinate system because the below code draws correct, which is the same d3d_wall code as above, im just trying to use a surface texture instead of sprite texture. which makes me think the problem is with the surface because the surface part is the only new thing.
Code:
d3d_draw_wall(x1,y1,16,x2,y2,0,sprite_get_texture(sprite4,spritedir),1,1);
 
Ok, after testing this myslef, I think I've found the source of the main problem... i.e. things going invisible. using surface_set_target(), although this behavoir is undocumented as far as I know, will reset the view (maybe the projection as well).

So you want to make sure that after you have drawn to your surface, and used surface_reset_target, you then set the view and projection. You're probably using d3d_set_projection_ext, right? Use it after you have finished drawing TO your surface (and done surface_reset_target). Then you draw your 3d stuff.
 
Last edited:
D

Dengar

Guest
still not working. I tried moving it all to the players draw event. with the wall code before the projection=nothing happens. wall code after the projection=view goes 2d.
ive also tried moving it to the draw begin and end events. ive double checked origins and anything else I can think of. it seems so simple. but still doesn't work.

in a seperate object I create a surface that I draw d3d walls to for the surface_get_pixel trick for detecting mouse clicks in a 3d space and that works so im stumped asto why this doesn't work. do I need to switch to 2d mode somewhere when adding sprites and text to a surface or something maybe?

------------------------------------------------------------------------
edit
------------------------------------------------------------------------
so after more fiddling, I still cant get it to work however you remember when I said that even a separate d3d_wall I had aslo went invisible, well I fount it. its being drawn on the 2d plane somewhere. I can see it when I look up in the sky, I don't use a roof.

--------------------------------------
nother edit
--------------------------------------
alright so when I put the surface creation in the create event and only reference it in the draw event, everything works (except that the surface is flipped upside-down).
so I'm guessing I cant dynamically update the surface in the draw event.

another thing, im drawing 32x32 sprites to 3d using d3d_walls, what I'd like to do is create a computer screen that'll show what im typing. the initial issue is that that's a small area to be drawing text in and then it blurs when its used in 3d. any thoughts?
------------------------------------------------------------------------
more issues
------------------------------------------------------------------------
Code:
 //create
su=surface_create(32, 32);
surface_set_target(su);
draw_clear_alpha(c_black,0.0);
draw_sprite(sprite4,spritedir,0,0);
draw_set_font(font0);
draw_text(0,0,"HELLO");
draw_set_font(-1);
surface_reset_target();

//draw
d3d_draw_wall(x1,y1,16,x2,y2,0,surface_get_texture(su),1,1);
the above code works, except the surface is flipped upside down.
however when I minimize the window and re-open it the surface is lost and its invisible so I changed to this and it doesn't work. can someone explain why?

Code:
//create
su=surface_create(32, 32);
surface_set_target(su);
draw_clear_alpha(c_black,0.0);
draw_sprite(sprite4,spritedir,0,0);
draw_set_font(font0);
draw_text(0,0,"HELLO");
draw_set_font(-1);
surface_reset_target();

//draw
if !surface_exists(su)
{
su=surface_create(32, 32);

surface_set_target(su);
draw_clear_alpha(c_black,0.0);
draw_sprite(sprite4,spritedir,0,0);
draw_set_font(font0);
draw_text(0,0,"HELLO");
draw_set_font(-1);
surface_reset_target();
}
d3d_draw_wall(x1,y1,16,x2,y2,0,surface_get_texture(su),1,1);
 
Last edited by a moderator:
the process should be

surface_set_target(surf_name);
d3d_set_projection_ortho(0,0,surf_width,surf_height,0); //this will make it so stuff isn't drawn upside down onto your surface
//draw stuff onto surface
surface_reset_target();

//then later set your view and projection
d3d_set_projection_ext(.... )

//and then draw your wall
d3d_draw_wall(... )

as long as you set the projection before trying to draw the walls, they should be drawn in the correct place.

If your in-game computer screen is too blurry, you need to use a larger surface for it.

When you minimize your game, the surfaces are lost. Meaning if you want them to remain visible, they have to be remade and the stuff that's supposed to be on them has to be redrawn. If a surface is loss, then surface_exists will return false. That'd be your cue that it needs rebuilding.
 
Top