3D [SOLVED] Problems drawing SURFACES in 3D

Hey all,

I've been fiddling around with GMS' 3D abilities lately. I've gotten the basics down and can create some neat looking little environments and whatnot. However, all of this is for implementation into a game project which makes heavy use of surface drawing. The problem is that every time I try adding a surface to my project, the whole 3D projection screws up!
Here's a picture of my test project w/o out the surfaces:

And here's a picture when I draw the little dude as a surface:

If I attempt to draw the CAM as a surface, I get a black screen.

Here's the Draw event of my CAM object (using HeartBeast's lovely 3D tutorial as a base). Imagine the surface stuff isn't there and you'll get what we see in the first image.
Code:
///draw camera
if !surface_exists(surf) {surf = surface_create(view_wview,view_hview);};
surface_set_target(surf);
{
    draw_clear_alpha(c_white,0);
   
    //settings
    d3d_set_zwriteenable(true);
    d3d_set_hidden(true);
       
    //vects
    xvect = lengthdir_x(32,dir);
    yvect = lengthdir_y(32,dir);
    zvect = lengthdir_y(32,zdir);
   
    d3d_set_projection(x,y,z,x+xvect,y+yvect,z+zvect,0,0,1);
    if (room == rm_movingTerrain || room == rm_movingGrid)
    {
        d3d_set_projection_ext(x,y,z,x+xvect,y+yvect,z+zvect,0,0,1,ang,global.aspect_ratio,1,32000);
    }
   
    //lighting
   
    d3d_set_lighting(true);
    d3d_set_shading(false);
    d3d_light_define_ambient(c_blue);
   
    d3d_light_define_point(0,room_width,room_height/2,100,max(room_width,room_height),c_fuchsia);
    d3d_light_enable(0,true);
   
    //fog
    d3d_set_fog(true,c_black,max(room_width,room_height)/4,max(room_width,room_height));
}
surface_reset_target();
draw_surface(surf,view_wview,view_yview);
And here's the code for the sprite dude:
Code:
if !surface_exists(surf) {surf = surface_create(sprite_width,sprite_height);}

surface_set_target(surf);
    {
    draw_clear_alpha(c_white,0);
    d3d_light_define_ambient(c_white);
    d3d_transform_set_identity();
    d3d_transform_add_rotation_x(90);
    d3d_transform_add_rotation_z(point_direction(x, y, CAM.x, CAM.y)+90);
    d3d_transform_add_translation(x, y, z+sprite_get_height(sprite_index))
    draw_sprite_ext(sprite_index, image_index, 0, 0, 1, 1, 0, c_white, 1);
    d3d_transform_set_identity();
    }
surface_reset_target();
draw_surface(surf,x,y)
I just have no idea what's going wrong!! Any help would be hELLA appreciated
 
J

Jfun300

Guest
In the surface you have to set the projection for the camera before drawing anything that's 3D.
 
In the surface you have to set the projection for the camera before drawing anything that's 3D.
You may notice that in my CAM code I do set the projection even when drawing to the surface. Even when I remove all other instances with surfaces attached, the problem (a flat projection) persists. I tried adding a projection to the sprite object, in fact the very same projection as in CAM, but nonetheless the problem persists. That is with or without drawing CAM to a surface.
 

Misu

The forum's immigrant
Ok... here is your prob... you are drawing the surface not onto the screen but onto the 3D base (which will either return black screen or nothing)

Within same cam object, within same surface, you must draw projection then draw everything else (models) afterwards (still within surface).

After that, you must draw the surface under ortho projection or in draw gui. If you dont do like that, you wont get anything. And when you do... remember to set fog and lighting to false when drawing the surface onto the screen, then reactivate it after its drawn.
 
Ok... here is your prob... you are drawing the surface not onto the screen but onto the 3D base (which will either return black screen or nothing)

Within same cam object, within same surface, you must draw projection then draw everything else (models) afterwards (still within surface).

After that, you must draw the surface under ortho projection or in draw gui. If you dont do like that, you wont get anything. And when you do... remember to set fog and lighting to false when drawing the surface onto the screen, then reactivate it after its drawn.
Excellent excellent excellent!! This worked! Many thanks
 
Top