• 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!

3D Drawing 3D to a surface

M

Mooshim

Guest
So I'm trying to create a program that renders an image and saves it in your folder.
The issue I'm having is that rather than rendering things relative to distance and what's in front of what, it's rendering it from which object I draw first.
http://i.imgur.com/M80crQM.png
(The hands are part of the head model because of their colour) As you can see from the code below, it draws Legs>Torso>Head, and creates that.

Is there anyway I can configure this so that it draws it all correctly, or should I just change the way I've made the models?

Create Event:
Code:
{
  d3d_start();
  display_mouse_set(display_get_width()/2,display_get_height()/2);
  d3d_set_perspective(true);
  x = 0
  y = 0
  
  head = d3d_model_create();
  d3d_model_load(head,"Head.d3d");
  face = background_get_texture(tex_face);

  torso = d3d_model_create();
  d3d_model_load(torso,"Torso.d3d");
  shirt = background_get_texture(tex_shirt);
  
  legs = d3d_model_create();
  d3d_model_load(legs,"Legs.d3d");
  pants = background_get_texture(tex_pants);
  
  render = surface_create(512,512);
}
Draw Event:
Code:
surface_set_target(render);
d3d_set_hidden(true);
d3d_set_lighting(true);
d3d_set_shading(true);
d3d_set_culling(false);
texture_set_interpolation(true);
d3d_light_define_ambient(make_color_rgb(240,240,240));
d3d_set_projection_ext(x,y,6,x+cos(point_direction(x,y,-10,25)*pi/180),y-sin(point_direction(x,y,-10,25)*pi/180),5.75,0,0,1,45,room_width/room_height,1,100);

d3d_light_define_point(1,-4,10,6,100,c_white);
d3d_light_enable(1,1);

d3d_transform_set_identity();
d3d_transform_add_scaling(0.6,0.6,0.6);
d3d_transform_add_rotation_x(-90);
d3d_transform_add_translation(-4,10,0);
d3d_model_draw(legs,0,0,0,pants);
d3d_model_draw(torso,0,0,0,shirt);
d3d_model_draw(head,0,0,0,face);
d3d_transform_set_identity();

surface_reset_target();

surface_save(render,"ID.png");
draw_surface(render,0,0);
game_end();
Thanks
 

Joe Ellis

Member
It looks like somethings going wrong with the depth testing(the z buffer)

so the arms are being drawn over the torso even though they're inside it partially

Are you rendering the models in the draw gui event? this could be causing it as the z buffer is not enabled for this event I think, if theyre rendered in the normal draw event, or even the step event, it should be fine,

It could also be that you have disabled z write somewhere, and if this is the case all models will be drawn ontop of any that were drawn before it.

maybe put this before any models are rendered
d3d_zwriteenable=1

while I've mentioned drawing in the step event, I thought I'd let you know if you don't know already,

When you render stuff to a separate surface (not the application surface) you can draw stuff to it in any event, not just the draw event, as long as you actually draw the surface in one of the draw events, ei.
draw_surface(render,0,0); would best be being drawn in the draw gui event, as it will just place the surface over the top of the application surface, its also useful for compositing, where you set the blend mode to something different and make it blend with the main app surface, eg. shadows, being rendered into the other surface, and in the draw gui, set blend mode to subtract, then draw the surface.




Other than what I said above, I can't think what else could be causing it, maybe you could send me the project file, and I'll try and work out what's going on
 
Last edited:
M

Mooshim

Guest
Thanks for all the detail - Here's the project file;
https://www.mediafire.com/?oys6rj0iby2mn7u

I've tried what you suggested, though there's still no difference.
When I draw it normally (without the surface) there is no issues, so I am not too sure as to why there is a difference.
 

Joe Ellis

Member
yeah, I'll have a look.

I had a very similar problem when I first started using surfaces

I just tried it, and the models won't load for me, whether I use the surface or not I just get a blank screen.

Sorry, I dunno what to do,

Are you using gm 8.1? I'd recommend upgrading cus studio's got so many more features, and it might work on that.
 
Last edited:
Top