Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - Synthetic

Pages: [1] 2
I've been using version 6.248 of GL Basic for the longest time and didn't really need to upgrade it since it has worked fine with everything I threw at it. Well, I come to the point where I needed to do some extensive work with files and started using openfile() and it's related functions. What I found is that some of the READ functions work and some fail as in the compiled app just closes as soon as it starts. A similar close as if you referenced an array with an index that is out of it's bounds though that's just an example to maybe narrow down the issue at hand. It could just be something I'm over looking. Anyway, I decided to install the latest version 8.148 in hopes that it would be a bug that got fixed since the last version I was using but this also had the same behavior. A search brought up a few topics on the matter but they didn't bare any fruit.

Below is some sample code I wrote for this issue and it lists the commands that work and the ones that exhibit the problem. I did not test any of the WRITE commands yet though except WRITEUBYTE and it is working correctly. I mainly need to use the LONG versions of the functions. The test file I used is not included, it was only 2k containing some random text.

Code: (glbasic) [Select]
GLOBAL storage%[]; DIM storage[1]
GLOBAL storageieee
GLOBAL storage$
GLOBAL pos = 0

IF OPENFILE(1,"test.txt",1)
// Not working
READLONG 1,storage[pos]
//READULONG 1,storage[pos]
//READSHORTIEEE 1,storageieee
//READIEEE 1,storageieee
//READSTR 1,storage$,4

// Working
//READBYTE 1,storage[pos]
//READUBYTE 1,storage[pos]
//READWORD 1,storage[pos]
//READUWORD 1,storage[pos]
//READLINE 1,storage$

PRINT "Test: " + storage[pos],0,0
PRINT "Test: " + storage$,0,10

Code Snippets / PNG screenshots
« on: 2009-Sep-24 »
This creates screenshots in the PNG format. There would be more to say but that's all it does.

When this example starts, it allows you to take only one screen shot with the "=" key. You will find the
screenshot inside the same folder as this example binary named screenshot.png.

Please note there is NO error handling. If something screws up, especially with libpng, you will get
a program crash.

When calling the screenshot_png function, it will automatically determine your screen size. You only
have to supply a file name or a folder/directory along with file name you want to save the screenshot

All required headers are included and should be placed in the same folder where your source is located.
They are:
_mingw.h | stdarg.h | stddef.h | stdint.h | stdio.h | stdlib.h | and the sys folder with types.h


file$ - The name and path/name for the PNG image you would like to create.

Feel free to use, chop up or mangle this code for your own usage. It is supplied AS-IS and should be
used at your own risk!

I will probably add more to this such as PNG text info customizing etc and I'm always open to ideas.

[attachment deleted by admin]

GLBasic - en / libpng calls
« on: 2009-Sep-16 »
I need to directly access the libpng functions so I can manually write PNG images via inline. I've added ones for OpenGL without a problem but I'm getting problems with libpng. For example the function png_create_write_struct takes 4 arguments but I'm getting this error output:

Code: (glbasic) [Select]
C:\DOCUME~1\SYNTHE~1.SYN\LOCALS~1\Temp\glbasic\gpc_tempa.cpp: In function `DGInt __GLBASIC__::png_create_write_struct()':
C:\DOCUME~1\SYNTHE~1.SYN\LOCALS~1\Temp\glbasic\gpc_tempa.cpp:95: error: too many arguments to function `DGInt __GLBASIC__::png_create_write_struct()'
C:\DOCUME~1\SYNTHE~1.SYN\LOCALS~1\Temp\glbasic\gpc_tempa.cpp:99: error: at this point in file

This is the code I have so far:

Code: (glbasic) [Select]
#define PNG_LIBPNG_VER_STRING "1.2.6"
extern "C"
void __stdcall png_create_write_struct(char,int,int,int);
namespace __GLBASIC__


FUNCTION png_create_write_struct:
        LOCAL ptr
ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,0,0,0);
        return ptr

I've downloaded version 1.2.6 of libpng and looked to make sure the function takes 4 args which it does so I don't get why it's saying too many arguments to function. Is it possible that the libpng library GLBasic uses is customized?

GLBasic - en / Clipboard - GlobalAlloc fails
« on: 2009-Apr-24 »
Basically I'm just trying to read regular text (CF_TEXT) from the Windows clipboard but as soon as I pass the handle to GlobalLock, it crashes. No errors are being thrown when compiling and this code should work. Any ideas?  =D Sample code below.

Code: (glbasic) [Select]



FUNCTION get_clipboard:
if(IsClipboardFormatAvailable(1) && OpenClipboard(GLBASIC_HWND()))
hData = GetClipboardData(1);
if(hData != NULL)
char *clipboard_data = (char*) GlobalLock(hData);

GLBasic - en / UV Mapping Problem - Solved
« on: 2009-Apr-04 »
I did some searching for this problem but found no concrete resolution to my problem. I have some models I made in AC3D, of which the textures are mapped with the TCE tool. The models show up just fine when loaded with GLBasic but as soon as I apply the texture, it appears that all coordinate data had been lost in the conversion to the .ddd format. I used the AC3D .ddd export plugin, an older version as well as the latest and also tried exporting to formats supported by the converter in GLBasic for conversion. All result in incorrectly mapped textures. I have spent the majority of the day trying to figure this out and it's driving me up the wall.  ;) More than likely it is something painfully obvious in AC3D that I'm overlooking.  ::) Any help is greatly appreciated.

This is a fairly simple 3rd person camera system found in many games. I've added documentation so you can see what's going on and I've also used easy to read variable names too as you navigate through the workings. This mainly focuses on creating a 3rd person camera but also includes things like timer based movement. I do plan on adding more features later and I'm always open to suggestions and optimizations.

Here is the media if you don't want to bother with the rar:

Code: (glbasic) [Select]
// =================================================================================================
// GLBasic 3rd Person Camera
// By: Synthetic
// - This is a fairly simple 3rd person camera system found in many games. I've added documentation
//   so you can see what's going on and I've also used easy to read variable names too as you
//   navigate through the workings. This mainly focuses on creating a 3rd person camera but also
//   includes things like timer based movement.
// - I do plan on adding more features later and I'm always open to suggestions and optimizations.
// ===========================
// ===========================
// Mouse Look
// - Hold the right mouse button to freely move around the character entity 360 degrees on the x/z
//   axis. Y axis view curves from overhead to up close around ground level.
// Movement Keys
// - Movement is done by rotating character entity via A/D and using W/S for forward/reverse.
// ===========================
// ===========================
// - The land generation code was taken from Gernot's Islands demo and modified slightly.
// =================================================================================================
// Load media
// =================================================================================================

LOADSPRITE "land.png",1
LOADSPRITE "cursor1.png",2
LOADSPRITE "cursor2.png",3

// =================================================================================================
// Declare global variables and values
// =================================================================================================

nil = 0 // Declared to keep compiler from throwing a warning
mouse_x = 0 // Declared to keep compiler from throwing a warning
mouse_y = 0 // Declared to keep compiler from throwing a warning
char_pos_y = 0 // Declared to keep compiler from throwing a warning

start_time = GETTIMERALL() // Grab intital time for calculating FPS
current_time = GETTIMERALL() // Grab intital time for calculating timer based movement

cam_mouse_x = 90 // Set camera starting view angle
cam_mouse_y = 32 // Set camera starting position on y axis
camera_near = 100 // Min distance from camera that will be drawn on screen
camera_far = 6000 // Max distance from camera that will be drawn on screen
camera_distance = 2500 // Adjusts how big of an orbit camera will rotate from character
distance_fog = 1 // Enable or disable distance fog 0 = off | 1 = on
fog_color = RGB(200,200,200) // Sets the color of the distance fog
fog_near = 1000 // Sets distance from camera that the fog starts
fog_far = 3000 // Sets ending distance of fog
light_color = RGB(255,255,255) // Sets ambient world lighting color
movement_speed = 150 // Sets how fast character moves
rotation_speed = 250 // Sets how fast character turns/changes direction

c1 = RGB(255,255,255) // One of the colors for our character object
c2 = RGB(00,150,255) // One of the colors for our character object
c3 = RGB(200,0,0) // One of the colors for our character object
c4 = RGB(0x50, 0x70, 0xff) // Color for the fake skybox
sky_box_size = 2000 // Sets the size of the fake skybox

// =================================================================================================
// Create Objects, Land and others
// =================================================================================================

// Generic entity (player) mmm...triangles...cheese filled torilla triangles!
X_OBJADDVERTEX   0,   0,   0,   0,0,c1
X_OBJADDVERTEX   0,  -1,   0,   0,0,c2
X_OBJADDVERTEX -10,   0,   2,   0,0,c1
X_OBJADDVERTEX -10,  -1,   2,   0,0,c2
X_OBJADDVERTEX -10,   0,  -2,   0,0,c1
X_OBJADDVERTEX -10,  -1,  -2,   0,0,c2
X_OBJADDVERTEX   0,   0,   0,   0,0,c2
X_OBJADDVERTEX -10,  -1,  -2,   0,0,c2
X_OBJADDVERTEX -10,  -1,   2,   0,0,c2
X_OBJADDVERTEX   0,  -1,   0,   0,0,c2

X_OBJADDVERTEX   0,  .1,   0,   0,0,c3
X_OBJADDVERTEX -10,  .1,  .5,   0,0,c3
X_OBJADDVERTEX -10, -.1, -.5,   0,0,c3

// Sky Box
X_OBJADDVERTEX  sky_box_size, -sky_box_size,  sky_box_size, 1,0,c4
X_OBJADDVERTEX -sky_box_size, -sky_box_size,  sky_box_size, 0,0,c4
X_OBJADDVERTEX  sky_box_size,  sky_box_size,  sky_box_size, 1,1,c4
X_OBJADDVERTEX -sky_box_size,  sky_box_size,  sky_box_size, 0,1,c4
X_OBJADDVERTEX -sky_box_size,  sky_box_size, -sky_box_size, 1,1,c4
X_OBJADDVERTEX -sky_box_size, -sky_box_size, -sky_box_size, 1,0,c4
X_OBJADDVERTEX  sky_box_size,  sky_box_size, -sky_box_size, 0,1,c4
X_OBJADDVERTEX  sky_box_size, -sky_box_size, -sky_box_size, 0,0,c4
X_OBJADDVERTEX -sky_box_size,  sky_box_size,  sky_box_size, 0,0,c4
X_OBJADDVERTEX -sky_box_size,  sky_box_size, -sky_box_size, 0,1,c4
X_OBJADDVERTEX  sky_box_size,  sky_box_size,  sky_box_size, 1,0,c4
X_OBJADDVERTEX  sky_box_size,  sky_box_size, -sky_box_size, 1,1,c4
X_OBJADDVERTEX  sky_box_size, -sky_box_size, -sky_box_size, 0,1,c4
X_OBJADDVERTEX -sky_box_size, -sky_box_size, -sky_box_size, 1,1,c4
X_OBJADDVERTEX  sky_box_size, -sky_box_size,  sky_box_size, 0,0,c4
X_OBJADDVERTEX -sky_box_size, -sky_box_size,  sky_box_size, 1,0,c4
X_OBJADDVERTEX  sky_box_size,  sky_box_size, -sky_box_size, 1,1,c4
X_OBJADDVERTEX  sky_box_size, -sky_box_size, -sky_box_size, 1,0,c4
X_OBJADDVERTEX  sky_box_size,  sky_box_size,  sky_box_size, 0,1,c4
X_OBJADDVERTEX  sky_box_size, -sky_box_size,  sky_box_size, 0,0,c4
X_OBJADDVERTEX -sky_box_size, -sky_box_size,  sky_box_size, 1,0,c4
X_OBJADDVERTEX -sky_box_size, -sky_box_size, -sky_box_size, 0,0,c4
X_OBJADDVERTEX -sky_box_size,  sky_box_size,  sky_box_size, 1,1,c4
X_OBJADDVERTEX -sky_box_size,  sky_box_size, -sky_box_size, 0,1,c4

// =================================================================================================
// Create land map
// =================================================================================================

DIM Height[MAXX+1][MAXY+1]


FOR n=0 TO 220
xs = RND(MAXX)
ys = RND(MAXY)

FOR n=0 TO 7
xs = RND(MAXX)
xe = xs+RND(MAXX/2)+1; IF xe>MAXX-1 THEN xe=MAXX-1
ys = RND(MAXY)
xe = ys+RND(MAXY/2)+1; IF ye>MAXY-1 THEN ye=MAXY-1

DrawMap(1, 2)

// =================================================================================================
// Main
// =================================================================================================


// =============================================================
// Setup camera position based on mouse
// =============================================================

// OK, so since this is going to be 3rd person with mouse look that orbits around the character,
// we need to keep track of mouse movement. You can do this by setting up a couple variables as
// counters. What they will be counting is the velocity (speed & direction) of the mouse x/y axis.
// To get this we use the mouseaxis() command. With that, our end result will be a camera that
// moves with how fast we move our mouse but there is more before we can get useable coordinates.
// Now the next step is to keep things within range. While it's not necessary here, it keeps things
// neater so to speak and can be used for limiting range which is what I did with the y axis.
// I took it a bit different though for the y axis so as to curve from up close to an overhead view.
// of the player. It's not completely perfect for what I wanted but will work here to give an idea
// of the process. Generally in a world based game with ground, you wouldn't want to spin all the
// way around on the y axis and have the camera travel under the floor. On a more advanced note,
// you can even do collision checking in regards to the height of the map at the location of the
// camera to keep it from clipping into say a steep mountain side as you walk down it. Back to the
// explaination here. If you have never messed with this stuff, you might wonder how were going to
// take our mouse counters and convert that to 3d space coordinates. This is actually very easy
// thanks to two simple friends from Trigonometry. Sin and Cos. I should punch myself for that.
// Anyway, I won't explain them but what you need to know is that they will give us usable
// coordinates for our camera. One thing we have to do though is consider our third dimension
// which is depth. While 2D is x and y, 3D also has z. In the GLBasic world and many others, x is
// left to right, y is up and down, and z is in and out so to speak. If you have trouble visualising
// this, refer to Graphics (3D) in the GLBasic help. So our y axis becomes z in 3D space. On to the
// actual math, camera position x is derived by using Sin on our mouse x counter and camera position
// z is derived by using Cos on our mouse x counter. One more step is needed though and that's the
// distance of the camera from the character. By looking below you should have an idea of the formula:
// 3d_position_x = distance * sin(mouse_x)
// 3d_position_y = distance * cos(mouse_x)
// The distance is how far we will be doing our rotation or orbit at. A higher amount would be
// farther away from the character and a lower would be closer. On to the last part here, You will
// notice that I have factored in the mouse y counter to add some curving like I mentioned before
// instead of just moving up and down on the y axis. I would suggest reading up on some Trig if you
// don't know it and want to get a better grasp of the types of curves you might want. Google is your
// friend. :D

// Keep track of mouse coordinates for our camera on right click
cam_mouse_x = cam_mouse_x - MOUSEAXIS(0)
cam_mouse_y = cam_mouse_y + MOUSEAXIS(1)
IF cam_mouse_x < 0 THEN cam_mouse_x = cam_mouse_x + 360
IF cam_mouse_x > 360 THEN cam_mouse_x = cam_mouse_x - 360
IF cam_mouse_y < 32 THEN cam_mouse_y = 32
IF cam_mouse_y > 719 THEN cam_mouse_y = 719

// Calculate camera position in regards to mouse coordinates
cam_pos_x = camera_distance * SIN(cam_mouse_x) * SIN(cam_mouse_y / 4 ) / 3
cam_pos_z = camera_distance * COS(cam_mouse_x) * SIN(cam_mouse_y / 4 ) / 3

// =============================================================
// Setup movement with the WASD keys
// =============================================================

// For movement, I have created a system that uses a directional vector. Depending on your direction,
// you will move forward in that direction and the camera will follow. First thing to setup is the
// rotation which is easy as checking the A and D keys and increasing or decreasing a counter depending
// on which key is pressed. Very simple. As before with the mouse looking, keep the direction
// within 360 degrees. Then just get the numbers via Cos and Sin and multiply those by how fast we want
// to move. The formula for the movement is:
// speed * position
// You then create variables that will hold the increased or decreased amount which will be added to
// the cameras final position. There is also something at work here which is important. The variable
// frame_delay_amount. This is the number used to calculate timer based movement. It is used to
// compensate movement speed on slower computers. For example, say your computer is slower than mine.
// On my computer the character turns a perfect 360 degrees every second. On yours, it is every 4
// seconds. What timer based movement does is allow us to take the amount you should have turned in
// x amount of time and add in the missing movement so you are also turing 360 degrees every second.
// How to get the delay amount will be found later on but the basic formula for your time compensated
// movement is:
// speed * delay between frames
// This also fixes the problem of moving slower in a scene with lots of 3D objects or too fast in a
// scene with vary few 3D objects to draw. Consistancy is a good thing.

// A - Rotate character counter clockwise
IF KEY(30) = 1
char_direction = char_direction - rotation_speed * frame_delay_amount
// D - Rotate character clockwise
IF KEY(32) = 1
char_direction = char_direction + rotation_speed * frame_delay_amount

// Keep character rotation within 360 degrees
IF char_direction < 0 THEN char_direction = char_direction + 360
IF char_direction > 360 THEN char_direction = char_direction - 360

// Get vector from character direction
char_rot_vec_x = COS(char_direction)
char_rot_vec_z = SIN(char_direction)

// W - Move character vector forward in regards to facing direction and speed
IF KEY(17) = 1
char_pos_x = char_pos_x + (movement_speed * char_rot_vec_x) * frame_delay_amount
char_pos_z = char_pos_z + (movement_speed * char_rot_vec_z) * frame_delay_amount
// S - Move character vector backwards in regards to facing direction and speed
IF KEY(31) = 1
char_pos_x = char_pos_x - (movement_speed * char_rot_vec_x) * frame_delay_amount
char_pos_z = char_pos_z - (movement_speed * char_rot_vec_z) * frame_delay_amount

// =============================================================
// Setup 3D World
// =============================================================

// So in the movement section we calculated our movement and ended up with the numbers needed to
// move our character around. Now it's time to get the camera to follow that. All we have to do
// is subtract the camera's current x and z coorinates from the character's x and z coordinates
// for the final camera position and do the same for the camera's view but instead of subtract,
// we add them. The rest is fairly straight forward but there is one more section about getting
// the delay time for timer based movement below.

// Calculate final camera position and view vectors in regards to character position
cam_final_pos_x = char_pos_x - cam_pos_x
cam_final_pos_y = cam_mouse_y
cam_final_pos_z = char_pos_z - cam_pos_z
cam_final_view_x = char_pos_x + cam_pos_x
cam_final_view_y = 0
cam_final_view_z = char_pos_z + cam_pos_z

X_MAKE3D camera_near, camera_far, 45
X_CAMERA cam_final_pos_x, cam_final_pos_y, cam_final_pos_z, cam_final_view_x, cam_final_view_y, cam_final_view_z

// Make our cheap skybox - Just for looks, not functional

// Draw Character Entity and position
X_CULLMODE 0 // Set to 0 because we can view some of the backsides
X_MOVEMENT char_pos_x,0,char_pos_z
X_ROTATION char_direction,0,-10,0
X_MOVEMENT char_pos_x,0,char_pos_z
X_ROTATION char_direction,0,-10,0

// Create distance fog
IF distance_fog THEN X_FOG fog_color, FALSE, fog_near, fog_far

// Draw Ground
X_CULLMODE 1 // Set to 1 becaus we don't need to draw the underneath of the ground
X_ROTATION 0,0,0,0

// Setup Lighting
X_AMBIENT_LT 2, light_color

// =============================================================
// Setup 2D
// =============================================================


// Get FPS
fps_time = GETTIMERALL()
IF start_time + 1000 > fps_time
INC fps_counter,1
start_time = GETTIMERALL()
fps_out = fps_counter
fps_counter = 0

// Print out some info
PRINT "3rd Person Camera by Synthetic o.O",0,0
PRINT "FPS                     : " + fps_out,0,20
PRINT "Delay Per Frame         : " + frame_delay,0,40
PRINT "Mouse Look X            : " + cam_mouse_x,0,60
PRINT "Mouse Look Y            : " + cam_mouse_y,0,80
PRINT "Camera Position X       : " + cam_final_pos_x,0,100
PRINT "Camera Position Y       : " + cam_final_pos_y,0,120
PRINT "Camera Position Z       : " + cam_final_pos_z,0,140
PRINT "Camera View X           : " + cam_final_view_x,0,160
PRINT "Camera View Y           : " + cam_final_view_y,0,180
PRINT "Camera View Z           : " + cam_final_view_z,0,200
PRINT "Character Direction     : " + char_direction,0,220
PRINT "Character Position X    : " + char_pos_x,0,240
PRINT "Character Position Y    : " + char_pos_y,0,260
PRINT "Character Position Z    : " + char_pos_z,0,280

// Setup mouse cursor
MOUSESTATE mouse_x,mouse_y,nil,nil // Get mouse x,y coordinates,
IF MOUSEAXIS(4) // Show movement cursor when right mouse button is held.
DRAWSPRITE 3,mouse_x,mouse_y
ELSE // Show standard cursor when right mouse button isn't held.
DRAWSPRITE 2,mouse_x,mouse_y

// To get our time delay for calculating timer based movement we need to keep track of two variables.
        // old_time and current_time. old_time is the time it was before the program completed a loop. current_time
// is the time it is now after the loop has gone through. To get the difference, it's just simple subtraction.
// current_time - old_time which gives us how long in milliseconds it takes to process a full program loop.
// Then by dividing this by 1000 (1000 ms = 1 second) we are telling it to give us a number we can use
// to calculate our movement compensation needed for every second gone by.

// Setup counters for time based movement
old_time = current_time
    current_time = GETTIMERALL()
    frame_delay = current_time - old_time
    frame_delay_amount = frame_delay / 1000.0

// =============================================================
// Create Land Map Function
// =============================================================
FUNCTION DrawMap: id_ddd, ft
LOCAL sc, mvx, mvy, x, y, col


sc = 200
mvx = sc * MAXX / 2
mvy = sc * MAXY / 2
X_OBJADDVERTEX x*sc-mvx, Height[x][1], 1*sc-mvy, ft*x, ft, col
X_OBJADDVERTEX (x+1)*sc-mvx, Height[x+1][y], y*sc-mvy, ft*(x+1), ft*y, col
X_OBJADDVERTEX x*sc-mvx, Height[x][y+1], (y+1)*sc-mvy, ft*x, ft*(y+1), col
X_OBJADDVERTEX (x+1)*sc-mvx, Height[x+1][y], y*sc-mvy, ft*(x+1), ft*y, col

[attachment deleted by admin]

GLBasic - en / 3rd person camera
« on: 2008-Jun-04 »
Been awhile.  :whistle: Anyway, I'm setting up a 3rd person view that changes in relation to mouse movement. So far I have x,z camera rotation and pointing working just fine:

What I'm having trouble with is adding in camera rotation and pointing from top to bottom (-90 to 90 degrees):

It's probably painfully obvious but it's been way too long since I played with trig. :noggin:

I was originally going to utilize the inline C feature of GLBasic to do this but I found a work around for now:

First you need to install the tobias DirectShow ogg filter. You can download this here -->


Next, you need to make an addition to your MCI Extentions.
Open up regedit and go to the following location -->
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\MCI Extensions
Now add a new String Value entry. For the name put in ogg. Type will already be set. Next, double click your new ogg entry and in the Data text field enter MPEGVideo. Click ok.

Everything is complete and you can now load and play ogg encoded audio files with the PLAYMUSIC command.

If you don't feel like venturing into your registry, I have provided a file for download that you can import into your registry to automaticly do the above for you. -->

ogg.reg - Right click and save as / save link as etc. depending on your browser.

Once saved, just double click it and it will bring up a window that says "Are you sure you want to add the information in" along with the files location. Click yes and it's done.

Another thing to note is that the tobias directshow filter can be included with your program and only requires you to put the disclaimer and copyright info in the documentation for your program. When you install the filter, it gives the specific information.

BTW, this is for Windows. The download link is now working again as the river's past page was removed.

I'm getting the following message when attempting to play an Ogg file through GLBASIC:

The specified file cannot be played on the specified MCI device. The file may be corrupt, not in the correct format, or no fil - The rest of the message is cut off here.

Here is the code I'm using:


As I understand it from the help, it should be able to play it. I have the Ogg Vorbis codec installed as I can play this same file via media player. Any ideas?

Code Snippets / Up Time Counter
« on: 2006-Jul-17 »
// --------------------------------- //
// Project: Up Time Counter
// Start: Sunday, July 16, 2006
// IDE Version: 3.179
// Here's another useful bit of code I came up with if you need a time counter.
// It counts seconds, minutes and hours.

//Grab starting timer position
//This gets the current timer position to start counting from.
//It has to be put where you want timing to start and should only be run once IE
//before the main loop or as the first part of the code in your program.
starttimesec = GETTIMERALL()
starttimemin = GETTIMERALL()
starttimehour = GETTIMERALL()

//Get temporary timer position minus the starting timer position.
//This gives us only the amount that has changed since the starting timer position
//was grabbed.
tempsec = GETTIMERALL() - starttimesec
tempmin = GETTIMERALL() - starttimemin
temphour = GETTIMERALL() - starttimehour

//Since GETTIMERALL() returns 1000ths of a second we divide by 1000 to get 1 second
//Not part of the actual code but to get minutes we need 60 total 1000ths of a second to = 1 min
//so we get 60000 by multiplying 60 x 1000.
//Similar with hours but since we now need 60 total minutes, that is 60 times the 60 x 1000ths
//(1min) which gives us 3600000 to divide by. If I lost you, don't worry, my description isn't that great.
//Also, GETTIMERALL() gives us a real number so we must use INTEGER() to give us a whole
//number by cutting off everything past the decimal point.
seconds = INTEGER(tempsec / 1000)
minutes = INTEGER(tempmin / 60000)
hours = INTEGER(temphour / 3600000)

//This sets the starting time positions up to grab the current timer position for another count once
//minutes or seconds have reached 60.
//Since hours count up continually, we don't need to modify the starting position for them unless you
//wanted to add a counter for days, years, etc..
IF minutes > 59 THEN starttimemin = GETTIMERALL()
IF seconds > 59 THEN starttimesec = GETTIMERALL()

//This should be easy to figure out but we are just pasting the timer results to
//the screen and then telling it to update so it can be seen.
PRINT "Up Time: " + hours + "h" + minutes + "m" + seconds + "s",200,100

GLBasic - en / Sprite RGB Modification
« on: 2006-Jul-10 »
I'm looking for a way to alter the RGB values of a sprite while preserving the transparency and be able to paste different RGB altered versions on screen at once. This would reduce the number of sprites used as I currently have multiple sprites of the same image, just a different color being loaded. Altering RGB will also give the abillity to have a much, much wider range of color possibilities. Is there an easy solution to this?

On another note, I just made my purchase for the Premium version and am eagerly looking forward to resuming my project. =)

Well, I thought that there was around a 4k limit to the amount of sprites that you could load. I was wrong. =D Playing around a bit, I was able to load more but found out some strange things. First, a sprite with ID number 4096 causes the compiled program to not run. I figured it was just the max that it supported but was able to narrow it down to 4096 being the culprit. I tried several different bitmap images to see if it made a difference but no luck. This is the code here:

LOADSPRITE "1.bmp",4096
SPRITE 4096,0,0

It will just freeze at "Loading..."

Next I tried to load more sprites thinking that just #4096 was a bad apple. This is what I came up with after experimenting.

It would correctly load and display sprites that had IDs in these number ranges with no problems:
0 - 4079
9000 - 12271
16400 - 20000

Now these number ranges for sprite IDs gave me all sorts of weird problems such as displaying half sized images of the loaded sprites in non specified locations on screen, messing up the built in font, showing the whole built in font on screen, hang on "Loading.." or just causing all sprites and the "Loading..." to not even show at all:
4080 - 8999
12272 - 16399

I didn't bother going any higher than 20k. Loading a sprite with an ID of just one of the numbers from the bad sets depending on which one it was, would work but not alot of them. It would take a long time :P just to test each and every number so those bad ranges are approximate. I used a for/next loop until I got working ranges with no problems.
Using an ID number of 4080 for a sprite causes any text to show as parts of that loaded sprite instead of the built in font. I tested this with several versions of GLBasic including 3.011 all with same results and on my other system just to make sure my RAM or anything else didn't decide to go section 8 on me.

GLBasic - en / Playsound and volume
« on: 2005-Dec-20 »
I tried adjusting the volume on a sound but it didn't do anything. I used a range from .0 to 1 with no effect. I noticed that in the tutorial it had said that it only had two arguments, the file name and stereo position while the playsound in the commands list showed it had a third for volume. It also shows volume as an option at the bottom in the editor. Has this not been implemented yet? Also, will there be volume support for music?

Code Snippets / Adjustable HP Bar
« on: 2005-Dec-18 »
// --------------------------------- //
// Project: Health Bar
// Start: Sunday, December 18, 2005
// IDE Version: 2.50519

// This little function will make an adjustable bar good for health points in
// a game or just about anything else you can think of.
// The function breaks down as follows:
// HBhp - This is the current amount of hp your character has.
// HBhpmax - This is the max amount of hp your character has.
// HBspnum - This is the sprite number of your bar graphic loaded with LOADSPRITE.
// HBbartype - A setting of 0 makes a horizontal bar, 1 makes a vertical bar.
// HBbarsize - This is the max size of the bar that you want it to adjust to.
// HBspwidth - This is the width of your bar graphic.
// HBspheight - This is the height of your bar graphic.
// HBx - This is the x position on screen you wish the bar to appear at.
// HBy - This is the y position on screen you wish the bar to appear at.

LOADSPRITE "bar.bmp",1 //For this test, I just used a red 12x12 bmp.

//Delcare variables
a = 1
horizontalhp = 250
verticalhp = 100
hpmax = 500

//Main Loop
WHILE a = 1
//Setup arrow keys to control current amount of hp
IF KEY(205) = 1 THEN horizontalhp = horizontalhp + 5
IF KEY(203) = 1 THEN horizontalhp = horizontalhp - 5
IF KEY(200) = 1 THEN verticalhp = verticalhp - 5
IF KEY(208) = 1 THEN verticalhp = verticalhp + 5
IF horizontalhp > hpmax THEN horizontalhp = hpmax // Keep horizontal hp from going over max amount
IF verticalhp > hpmax THEN verticalhp = hpmax // Keep vertical hp from going over max amount
IF horizontalhp < 0 THEN horizontalhp = 0 // Keep horizontal hp from goin under 0
IF verticalhp < 0 THEN verticalhp = 0 // Keep vertical hp from going under 0
//Call health bar function
HealthBar(horizontalhp,hpmax,1,0,100,12,12,0,150) //Make horizontal bar
HealthBar(verticalhp,hpmax,1,1,100,12,12,150,150) //Make vertical bar
//Show current hp for both bars
PRINT horizontalhp,0,150
PRINT verticalhp,150,150

FUNCTION HealthBar: HBhp,HBhpmax,HBspnum,HBbartype,HBbarsize,HBspwidth,HBspheight,HBx,HBy
//Setup HP bar
HBhpbar = (HBhp*HBbarsize)/HBhpmax
HBhpbarx = HBhpbar-INTEGER(HBhpbar)
IF HBhpbarx <= .5
 HBhpbarresult = INTEGER(HBhpbar-1)
 HBhpbarresult = INTEGER(HBhpbar)
IF HBbartype = 0 THEN STRETCHSPRITE HBspnum,HBx,HBy,HBhpbarresult,HBspheight
IF HBbartype = 1 THEN STRETCHSPRITE HBspnum,HBx,HBy,HBspwidth,HBhpbarresult

I ran into a limit of 4k sprites. I tried to get around this by using polyvectors and a tile set but couldn't figure them out completely so I searched the forums and found a post about animated sprites. In this thread GernotFrisch posted some sample code with a PSprite function. I tried it out, figured out somewhat how they work, and altered it to see if I could get it to do what I want but was unsucessful. Basically, I wanted to position the output at any x,y position on screen. I was able to move the Hello PSprite text up and down but not right and left by just a number. Spaces in the word variable worked but I was hoping to accomplish a way to position the output to any x position on screen not just the distance of a space. Is there something obvious I'm overlooking in positioning the polyvector output?

Pages: [1] 2