Beginner's corner

Top  Previous  Next

Mouse coordinates

 

Sometimes, especially when you are designing some panels or doing some beta testing, you will want to see the exact mouse coordinates on the screen, and that's exactly what the code below does.

 

aum48_shot_1

 

string temporary_str;
string coordinates_str;

 

text mcoordinates_txt // using the default font here
{
       string = coordinates_str;
       layer = 20;
       flags = visible;
}

 

starter display_coords()
{
       while (1)
       {
               str_for_num(temporary_str, mouse_pos.x); // convert mouse_pos.x to a string
               str_cpy(coordinates_str, "("); // add the first paranthesis
               str_cat(coordinates_str, temporary_str); // add mouse_pos.x to the string
               str_cat(coordinates_str, ","); // add a comma to separate mouse_pos.x and mouse_pos.y
               str_for_num(temporary_str, mouse_pos.y); // convert mouse_pos.y to a string
               str_cat(coordinates_str, temporary_str); // add mouse_pos.y to the string
               str_cat(coordinates_str, ")"); // add the second paranthesis
               mcoordinates_txt.pos_x = mouse_pos.x + 15; // keep the text in the lower right corner
               mcoordinates_txt.pos_y = mouse_pos.y + 15; // in relation to the mouse position
               wait (1);
       }
}

 

I have used a simple text definition because the coordinates are displayed by coordinates_str. The starter function converts mouse_pos.x (which is a number) to a string, adds the first parenthesis ( then adds mouse_pos.x to the string, adds a comma, converts mouse_pos.y to a string and adds it to coordinates_str as well. We add the second parenthesis ) and then we make sure that the text is kept 15 pixels to the right and 15 pixels below the pointer. That's it!

 

 

Get the vertex and pixel shader versions

 

aum48_shot_2

 

I have to admit that I don't feel too comfortable with all these different video cards that are available nowadays. If you want to create a great looking game you will need to make sure that all your customers have video cards with (let's say) VS = 2.0 and PS = 2.0. But will all of them have those modern cards? Hold on, I have just noticed that a card with VS = 2.0 and PS = 2.0 has become an obsolete video card already! ;)

The code from this article will display your video card's capabilities so be prepared to be thrilled or extremely disappointed.

 

string tmp_shader = " ";
string temp_str;
string displayed_str;

 

text shader_txt
{
       pos_x = 300;
       pos_y = 300;
       string = displayed_str;
       layer = 20;
}

 

The precious VS and PS values are given by d3d_shaderversion, which is returned by A6.31 or a newer version of it. I have defined a few strings and a text that will display the VS and PS values.

 

function display_shader_versions()
{
       str_for_num(tmp_shader, d3d_shaderversion); // convert d3d_shaderversion to a string
       str_cpy(temp_str, tmp_shader); // don't destroy tmp_shader; play with temp_str
       str_trunc(temp_str, 3); // cut the last 3 characters from temp_str (get the first digit of vertex shader version)
       str_cpy(displayed_str, "Vertex shader version: ");
       str_cat(displayed_str, temp_str);
       str_cat(displayed_str, "."); // add a dot
       str_cpy(temp_str, tmp_shader); // restore the initial d3d_shaderversion string
       str_trunc(temp_str, 2); // cut the last 2 characters from temp_str
       str_clip(temp_str, 1); // cut the first character from temp_str (we've got the second digit of the vertex shader version here)
       str_cat(displayed_str, temp_str);
       str_cat(displayed_str, "\n"); // move on to the following line of text
       str_cpy(temp_str, tmp_shader); // restore the initial d3d_shaderversion string one more time
       str_clip(temp_str, 2); // remove the first 2 characters from the string
       str_trunc(temp_str, 1); // remove the last character from the string
       str_cat(displayed_str, "Pixel shader version: ");
       str_cat(displayed_str, temp_str);
       str_cat(displayed_str, "."); // add the dot
       str_cpy(temp_str, tmp_shader); // load the initial d3d_shaderversion for the last time
       str_clip(temp_str, 3); // cut the first 3 characters from the string
       str_cat(displayed_str, temp_str); // all is ok now
       shader_txt.visible = on; // display the text
       sleep (5); // wait for 5 seconds
       shader_txt.visible = off; // hide the pane;
}

 

on_s = display_shader_versions;

 

The function above displays VS and PS for 5 seconds when the player presses the "S" key. The first line of code converts d3d_shaderversion, which is a number (1234 would mean VS = 1.2 and PS = 3.4) to a string. The following lines of code copy tmp_shader to temp_str, get the first digit for VS, copy the "Vertex shader version: " text to the string, add the first VS digit, and then a dot, the get the second VS digit and copy it to the same string. The things repeat for PS. These are the stages that show how the displayed_str string looks like while it is being built:

 

Vertex shader version:

 

Vertex shader version: 2

 

Vertex shader version: 2.

 

Vertex shader version: 2.0

 

Vertex shader version: 2.0
Pixel shader version:

 

Vertex shader version: 2.0
Pixel shader version: 2

 

Vertex shader version: 2.0
Pixel shader version: 2.

 

Vertex shader version: 2.0
Pixel shader version: 2.0