• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

Windows Problem converting d3d code when importing a project to GMS2.3

ze1

Member
Hi, I have a simple dungeon crawler project in GMS1 that used a bunch of d3d functions. When I imported that project into GMS2.3, the project conversion created new functions to replace the deprecated ones in GMS2.3, but it doesn't work when I run the game in GMS2.3. I've attached the pictures of the game both in GMS1 and GMS2.3.

Here are the converted functions below. They have the same names as their respective GMS D3D functions

__init_global
GML:
function __init_global() {
    gml_pragma( "global", "__init_global();");

    // set any global defaults
    layer_force_draw_depth(true,0);        // force all layers to draw at depth 0
    draw_set_colour( c_black );


}

d3d_start
GML:
/// @description d3d - enable 3d
function d3d_start() {

    var ret = global.__d3d;
    global.__d3d = true;
    //camera_apply(global.__d3dCamera);
    gpu_set_ztestenable(true);
    gpu_set_zwriteenable(true);
    return ret;



}
d3d_vertex_normal_texture
GML:
/// @description d3d - Defines a vertex for a textured primitive in 3D along with its corresponding normal.
/// @param x the x position
/// @param y the y position
/// @param z the z position
/// @param nx the normal x
/// @param ny the normal y
/// @param nz the normal z
/// @param u the normal u
/// @param v the normal v
function d3d_vertex_normal_texture(argument0, argument1, argument2, argument3, argument4, argument5, argument6, argument7) {

    vertex_position_3d( global.__d3dPrimBuffer, argument0, argument1, argument2 );
    vertex_normal( global.__d3dPrimBuffer, argument3, argument4, argument5 );
    vertex_colour( global.__d3dPrimBuffer, draw_get_colour(), draw_get_alpha() );
    vertex_texcoord( global.__d3dPrimBuffer, (argument6 * global.__d3dPrimTexW) + global.__d3dPrimTexX, (argument7 * global.__d3dPrimTexH) + global.__d3dPrimTexY );


}
d3d_set_projection
GML:
/// @description  @description d3d - set projection
/// @param xFrom    x of from position
/// @param yFrom    y of from position
/// @param zFrom    z of from position
/// @param xTo        x of to position
/// @param yTo        y of to position
/// @param zTo        z of to position
/// @param xUp        x of up vector
/// @param yUp        y of up vector
/// @param zUp        z of up vector
function d3d_set_projection(argument0, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8) {

    var m = matrix_build_lookat( argument0, argument1, argument2,
                                 argument3, argument4, argument5,
                                 argument6, argument7, argument8 );

    var cam = camera_get_active();
    camera_set_view_mat( cam, m );
    if( !global.__d3d ) {
        //apply default ortho projection
        var mproj = matrix_build_projection_ortho(camera_get_view_width(cam),camera_get_view_height(cam),1,32000);
        camera_set_proj_mat( cam, mproj);
    }
    camera_apply(cam);


}

d3d_set_fog
GML:
/// @description  d3d - set fog enable/disable and colour
/// @param enable true if enabled, false if disabled
/// @param colour    colour of the fog
/// @param near    distance to when fog starts
/// @param far    distance to when fog becomes absolute
function d3d_set_fog(argument0, argument1, argument2, argument3) {

    gpu_set_fog(argument0, argument1, argument2, argument3 );


}

d3d_primitive_begin_texture
GML:
/// @description  d3d - begin making a primitive stream
/// @param kind Primitive kind
/// @param tex Texture Index
function d3d_primitive_begin_texture(argument0, argument1) {

    if (global.__d3dPrimKind != -1) {
        show_debug_message( "ERROR : cannot begin a primitive before end called on previous")
    }

    global.__d3dPrimKind = argument0;
    global.__d3dPrimTex = argument1;
    var __uvs = texture_get_uvs(global.__d3dPrimTex);
    global.__d3dPrimTexX = __uvs[0];
    global.__d3dPrimTexY = __uvs[1];
    global.__d3dPrimTexW = __uvs[2] - __uvs[0];
    global.__d3dPrimTexH = __uvs[3] - __uvs[1];
    vertex_begin( global.__d3dPrimBuffer, global.__d3dPrimVF );


}

d3d_primitive_end
GML:
/// @description d3d - end the primitive stream
function d3d_primitive_end() {

    if (global.__d3dPrimKind != -1) {

        vertex_end( global.__d3dPrimBuffer );
        vertex_submit( global.__d3dPrimBuffer, global.__d3dPrimKind, global.__d3dPrimTex );

        // mark this as finished
        global.__d3dPrimKind = -1;
    } else {
        show_debug_message( "d3d_primitive_end :: with no d3d_primitive_begin ");
    }



}

d3d_draw_floor
GML:
/// @description Draws a simple 3D floor.
/// @param x1 The initial x coordinate of the floor.
/// @param y1 The initial y coordinate of the floor.
/// @param z1 The initial z coordinate of the floor.
/// @param x2 The opposite x coordinate of the floor.
/// @param y2 The opposite y coordinate of the floor.
/// @param z2 The opposite z coordinate of the floor.
/// @param tex The id of the texture to use (-1 for no texture)
/// @param hrepeat Amount of horizontal repetitions for the texture.
/// @param vrepeat Amount of vertical repetitions for the texture.
/// @returns
function d3d_draw_floor(argument0, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8) {

    var __x1 = argument0;
    var __y1 = argument1;
    var __z1 = argument2;
    var __x2 = argument3;
    var __y2 = argument4;
    var __z2 = argument5;
    var __tex = argument6;
    var __hrepeat = argument7;
    var __vrepeat = argument8;

    var __xdiff = __x2 - __x1;
    var __zdiff = __z2 - __z1;

    var __lsquared = (__xdiff * __xdiff) + (__zdiff * __zdiff);
    if (__lsquared == 0)
        return 0;
    
    var __l = sqrt(__lsquared);

    var __nx = -__zdiff / __l;
    var __nz = __xdiff / __l;

    var __oldrep = gpu_get_texrepeat();
    gpu_set_texrepeat(true)

    d3d_primitive_begin_texture(pr_trianglefan, __tex);

    d3d_vertex_normal_texture(__x1, __y1, __z1, __nx, 0, __nz, 0, 0);
    d3d_vertex_normal_texture(__x1, __y2, __z1, __nx, 0, __nz, 0, __vrepeat);
    d3d_vertex_normal_texture(__x2, __y2, __z2, __nx, 0, __nz, __hrepeat, __vrepeat);
    d3d_vertex_normal_texture(__x2, __y1, __z2, __nx, 0, __nz, __hrepeat, 0);

    d3d_primitive_end();

    gpu_set_texrepeat(__oldrep);


}
d3d_draw_block
GML:
/// @description Draws a simple 3D block.
/// @param x1 The initial x coordinate of the block.
/// @param y1 The initial y coordinate of the block.
/// @param z1 The initial z coordinate of the block.
/// @param x2 The opposite x coordinate of the block.
/// @param y2 The opposite y coordinate of the block.
/// @param z2 The opposite z coordinate of the block.
/// @param tex The id of the texture to use (-1 for no texture)
/// @param hrepeat Amount of horizontal repetitions for the texture.
/// @param vrepeat Amount of vertical repetitions for the texture.
/// @returns
function d3d_draw_block(argument0, argument1, argument2, argument3, argument4, argument5, argument6, argument7, argument8) {

    var __x1 = argument0;
    var __y1 = argument1;
    var __z1 = argument2;
    var __x2 = argument3;
    var __y2 = argument4;
    var __z2 = argument5;
    var __tex = argument6;
    var __hrepeat = argument7;
    var __vrepeat = argument8;

    var __oldrep = gpu_get_texrepeat();
    gpu_set_texrepeat(true)   

    d3d_primitive_begin_texture(pr_trianglelist, __tex);


    d3d_vertex_normal_texture(__x1, __y1, __z1, 0, 0, -1, 0, 0);
    d3d_vertex_normal_texture(__x1, __y2, __z1, 0, 0, -1, 0, __vrepeat);
    d3d_vertex_normal_texture(__x2, __y2, __z1, 0, 0, -1, __hrepeat, __vrepeat);

    d3d_vertex_normal_texture(__x2, __y2, __z1, 0, 0, -1, __hrepeat, __vrepeat);
    d3d_vertex_normal_texture(__x2, __y1, __z1, 0, 0, -1, __hrepeat, 0);
    d3d_vertex_normal_texture(__x1, __y1, __z1, 0, 0, -1, 0, 0);


    d3d_vertex_normal_texture(__x1, __y1, __z2, 0, 0, 1, 0, 0);
    d3d_vertex_normal_texture(__x2, __y1, __z2, 0, 0, 1, __hrepeat, 0);
    d3d_vertex_normal_texture(__x2, __y2, __z2, 0, 0, 1, __hrepeat, __vrepeat);

    d3d_vertex_normal_texture(__x2, __y2, __z2, 0, 0, 1, __hrepeat, __vrepeat);
    d3d_vertex_normal_texture(__x1, __y2, __z2, 0, 0, 1, 0, __vrepeat);
    d3d_vertex_normal_texture(__x1, __y1, __z2, 0, 0, 1, 0, 0);


    d3d_vertex_normal_texture(__x1, __y2, __z1, 0, 1, 0, 0, 0);
    d3d_vertex_normal_texture(__x1, __y2, __z2, 0, 1, 0, 0, __vrepeat);
    d3d_vertex_normal_texture(__x2, __y2, __z2, 0, 1, 0, __hrepeat, __vrepeat);

    d3d_vertex_normal_texture(__x2, __y2, __z2, 0, 1, 0, __hrepeat, __vrepeat);
    d3d_vertex_normal_texture(__x2, __y2, __z1, 0, 1, 0, __hrepeat, 0);
    d3d_vertex_normal_texture(__x1, __y2, __z1, 0, 1, 0, 0, 0);


    d3d_vertex_normal_texture(__x2, __y2, __z1, 1, 0, 0, 0, 0);
    d3d_vertex_normal_texture(__x2, __y2, __z2, 1, 0, 0, 0, __vrepeat);
    d3d_vertex_normal_texture(__x2, __y1, __z2, 1, 0, 0, __hrepeat, __vrepeat);

    d3d_vertex_normal_texture(__x2, __y1, __z2, 1, 0, 0, __hrepeat, __vrepeat);
    d3d_vertex_normal_texture(__x2, __y1, __z1, 1, 0, 0, __hrepeat, 0);
    d3d_vertex_normal_texture(__x2, __y2, __z1, 1, 0, 0, 0, 0);


    d3d_vertex_normal_texture(__x2, __y1, __z1, 0, -1, 0, 0, 0);
    d3d_vertex_normal_texture(__x2, __y1, __z2, 0, -1, 0, 0, __vrepeat);
    d3d_vertex_normal_texture(__x1, __y1, __z2, 0, -1, 0, __hrepeat, __vrepeat);

    d3d_vertex_normal_texture(__x1, __y1, __z2, 0, -1, 0, __hrepeat, __vrepeat);
    d3d_vertex_normal_texture(__x1, __y1, __z1, 0, -1, 0, __hrepeat, 0);
    d3d_vertex_normal_texture(__x2, __y1, __z1, 0, -1, 0, 0, 0);


    d3d_vertex_normal_texture(__x1, __y1, __z1, -1, 0, 0, 0, 0);
    d3d_vertex_normal_texture(__x1, __y1, __z2, -1, 0, 0, 0, __vrepeat);
    d3d_vertex_normal_texture(__x1, __y2, __z2, -1, 0, 0, __hrepeat, __vrepeat);

    d3d_vertex_normal_texture(__x1, __y2, __z2, -1, 0, 0, __hrepeat, __vrepeat);
    d3d_vertex_normal_texture(__x1, __y2, __z1, -1, 0, 0, __hrepeat, 0);
    d3d_vertex_normal_texture(__x1, __y1, __z1, -1, 0, 0, 0, 0);

    d3d_primitive_end();

    gpu_set_texrepeat(__oldrep);


}
 

Attachments

ze1

Member
Thanks for the reply! I did some more research and decided to change my approach based on what I've seen on a few websites. I'll share that info here in case anyone else has the same problem I did (it's kinda specific, so I doubt it'll be useful, but who knows). The d3d_start() function is basically the same as the one in the first post.

On the create event of the player object, add:
GML:
d3d_start();
camera = camera_create();
projMat = matrix_build_projection_perspective_fov(75, -view_get_wport(0)/view_get_hport(0), 1, 320);
camera_set_proj_mat(camera, projMat);
view_set_camera(0, camera);
camera_set_update_script(view_camera[0], camera_update_script);
And create another script called camera_update_script, then add this:
GML:
function camera_update_script(){
    var zz = obj_player.z;
    var xx = obj_player.x
    var yy = obj_player.y
   
    var vect_x = lengthdir_x(8, obj_player.face_direction+180)
    var vect_y = lengthdir_y(8, obj_player.face_direction+180)
    var vect_x2 = lengthdir_x(32, obj_player.face_direction)
    var vect_y2 = lengthdir_y(32, obj_player.face_direction)
    mLookat = matrix_build_lookat(xx+vect_x,yy+vect_y,zz, xx+vect_x2, yy+vect_y2, zz, 0,0,-1);
    camera_set_view_mat(view_camera[0], mLookat);
}

EDIT:
But now I have new problem: the world is upside down. I tried changing the field of vision angle from 75 to -75. It makes the world normal, but it reverses directions (if I increase the angle it goes right, instead of going left, like normal GMS2 direction). How can I fix that?
 
Last edited:
Top