Pages: 1
Author Topic: Using d3d_set_projection_ortho for HUD in 2d game. Stacking images.  (42,385 Views)
Offline (Unknown gender) intygamer

Member
Joined: Mar 2013
Posts: 77
View profile
Posted on: January 22, 2014, 01:23:32 AM
I am using d3d_set_projection_ortho as a HUD for my 2d game so it does not move while rest of screen is zooming or panning.  The depth of the object that draws this is lower than everthing else.  I have read rule of thumb is first shape or text will be stacked under sequencial shapes or text at same x,y position, last will be on top of everthing.  First I drew a rectangle, then drew a sprite over that.  In that order it worked.  If I reverse, the rectangle will be over the sprite.  Then I tried to draw a health bar over the rectangle and text over rectangle.  They will not show above rectangle in any order.

Draw Event:

draw_set_font(font_arial);
draw_set_color(c_black);
d3d_set_projection_ortho(0,0,view_wport[0],view_hport[0],0);
draw_rectangle(0,0,50,view_hport[0],false);
draw_sprite_ext(ship[0,p1_ship_number],0,25,30,.30,.30,90,c_white,1);
draw_healthbar(view_wport[0] - 75,65,view_wport[0] - 25,75,obj_switch_ship.p1_ship.hp,c_silver,c_red,c_red,1,true,false);
//draw_set_color(c_red);
//draw_text(view_wport[0] - 50,65,obj_switch_ship.p1_ship.hp);
//draw_set_color(c_black);


The rectangle is the background for the HUD.  Please tell me how to get healthbar or text showing ontop of rectangle.

Thanks
Joe
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #1 Posted on: January 22, 2014, 10:27:26 AM
Can you draw_healthbar in any case? Because that function hasn't been tested since the generalization rewrite, so maybe it is just broken. At least I haven't tested it.

And you could also use the GUI draw event now. It will automatically have all the projections set up.
Offline (Unknown gender) intygamer

Member
Joined: Mar 2013
Posts: 77
View profile
Reply #2 Posted on: January 22, 2014, 10:58:36 PM
I can draw the health bar, it just wont draw over the rectangle in the code above.  The same with text.  I have not updated from github since 2 months ago.  Was waiting for the issues with bad commits to github to be resolved before updating.  Probally by now they are resolved? 

I will try the GUI draw event.  Will this GUI draw event work like the draw event and all I will have to do is drag the code from draw event to GUI draw event?

Thanks
Joe
Offline (Unknown gender) Goombert

Developer
Joined: Jan 2013
Posts: 2,991
View profile
Reply #3 Posted on: January 23, 2014, 12:40:32 AM
This issue should not exist in the latest commits, intygamer, I can help you revert to a prior commit if anything that bad happens. But the latest version of the Portable ZIP is the first update since last month, because I was letting tons of bug fixes go in. So you could definitely try, it should be pretty stable.

The GUI event is processed after every objects draw event, and automatically sets the project. The size of the GUI layer by default is the size of the window, you can change it via display_set_gui_size
http://enigma-dev.org/docs/Wiki/Display_set_gui_size
Offline (Unknown gender) intygamer

Member
Joined: Mar 2013
Posts: 77
View profile
Reply #4 Posted on: January 24, 2014, 02:10:31 PM
Quote from: Robert B Colton on January 23, 2014, 12:40:32 AM
This issue should not exist in the latest commits, intygamer, I can help you revert to a prior commit if anything that bad happens. But the latest version of the Portable ZIP is the first update since last month, because I was letting tons of bug fixes go in. So you could definitely try, it should be pretty stable.

The GUI event is processed after every objects draw event, and automatically sets the project. The size of the GUI layer by default is the size of the window, you can change it via display_set_gui_size
http://enigma-dev.org/docs/Wiki/Display_set_gui_size
Yesterday I updated Enigma and LGM binaries Linux version.  I moved all the code from draw event to gui event and the black rectangle still draws over text and the health bar.

Also my view script for keeping 2 objects on the view port is not working after the update.

Here is a link to the script I am using.
http://yal.cc/gamemaker-view-following-two-objects-at-once/

Quote from: TheExDeus on January 22, 2014, 10:27:26 AM
Can you draw_healthbar in any case? Because that function hasn't been tested since the generalization rewrite, so maybe it is just broken. At least I haven't tested it.

And you could also use the GUI draw event now. It will automatically have all the projections set up.
The healthbar is working even after update.

Thanks to all
Joe
Offline (Unknown gender) Goombert

Developer
Joined: Jan 2013
Posts: 2,991
View profile
Reply #5 Posted on: January 24, 2014, 07:30:09 PM
Somebody messed with views intygamer, I'll get the fixed version over from GL3 today for you. In the meantime, can you provide a small GMK or EGM that exhibits this depth bug?
Offline (Unknown gender) intygamer

Member
Joined: Mar 2013
Posts: 77
View profile
Reply #6 Posted on: January 24, 2014, 10:35:28 PM
Quote from: Robert B Colton on January 24, 2014, 07:30:09 PM
Somebody messed with views intygamer, I'll get the fixed version over from GL3 today for you. In the meantime, can you provide a small GMK or EGM that exhibits this depth bug?

I attached the file.

Thanks
Joe
Offline (Unknown gender) Goombert

Developer
Joined: Jan 2013
Posts: 2,991
View profile
Reply #7 Posted on: January 25, 2014, 10:31:04 PM
I have merged Josh's GL3 screen redraw cleanup to OpenGL1 which fixes views stretching issue in the following pull request.
https://github.com/enigma-dev/enigma-dev/pull/626

I have also attempted to fix the depth issue but it appears fine.
This draws the rectangle on top.
Code (edl) Select

draw_healthbar(50, 50, 100, 100,50,c_silver,c_red,c_red,1,true,false);
draw_rectangle(0,0,150,150,false);

This draws the healthbar on top.
Code (edl) Select

draw_rectangle(0,0,150,150,false);
draw_healthbar(50, 50, 100, 100,50,c_silver,c_red,c_red,1,true,false);


So upon further investigation, you were drawing the rectangle over top of the healthbar.
Code (edl) Select

//Draw player2 hud
draw_rectangle(view_wport[0] - 50,0,view_wport[0],view_hport[0],false);  // this is overlapping the healthbar because the healthbar is drawn before this
draw_sprite_ext(s_player,1,view_wport[0] - 25,30,.30,.30,90,c_white,1);


The fixed version is right here, just stick this code in your GUI event.
Code (edl) Select

draw_set_font(font_arial);
draw_set_color(c_black);

//d3d_set_projection_ortho(0,0,view_wport[0],view_hport[0],0);

//Draw player1 hud
draw_rectangle(0,0,50,view_hport[0],false);
draw_sprite_ext(s_player,0,25,30,.30,.30,90,c_white,1);//spr,index,x,y,xscale,yscale,rot,colorblend,trans 1-0

//draw_healthbar(x1, y1, x2, y2, amount, backcol, mincol, maxcol, direction, showback, showborder)

//Draw player2 hud
draw_rectangle(view_wport[0] - 50,0,view_wport[0],view_hport[0],false);
draw_sprite_ext(s_player,1,view_wport[0] - 25,30,.30,.30,90,c_white,1);

draw_set_color(c_red);
draw_text(view_wport[0] - 65,100,o_player1.hp);
draw_set_color(c_black);
draw_healthbar(view_wport[0] - 75,65,view_wport[0] - 25,75,o_player1.hp,c_silver,c_red,c_red,1,true,false);

And you should get the following picture.

I have also attached the fixed GMK to my post.
Offline (Unknown gender) intygamer

Member
Joined: Mar 2013
Posts: 77
View profile
Reply #8 Posted on: January 26, 2014, 03:58:53 PM
I see what I did.  I put the code under the wrong rectangle, duh.  :-[

The Views work now!  :)

Thanks Robert  :)
Joe

Offline (Unknown gender) Goombert

Developer
Joined: Jan 2013
Posts: 2,991
View profile
Reply #9 Posted on: January 26, 2014, 07:15:10 PM
No problem, glad I could be of assistance.
Pages: 1