|
Post by Candle on Jul 4, 2004 23:00:29 GMT -5
I would like to make a few screensavers but I can't seem to find how to exit program if mouse moves . I'm new to this so if i ask a lot of dumb questions don't yell Thanks for any help .
|
|
|
Post by AHBanen on Jul 5, 2004 5:34:36 GMT -5
Candle, I take it you know that to create a functioning screensaver, that closes immediately when it should, you need to Create a Standalone .exe (from the Basic4GL File menu). When doing so you should choose from the Option tab of the window that then pops up: When the program finishes it should -> close immediately In the Screen Mode tab: Screen mode - use desktop Color mode - use desktop Select fullscreen (these are the settings that work for me) To detect the mouse movement do the following at the start of the program (that is including entering the main loop).
always end the program with:
As an example the nehe5.gb example from the Programs directory 'rebuild as screensaver' using the above method:
Have fun creating screensavers using Basic4GL!
André
Note: Basic4GL offers no options to use run time arguments to the created exe. This may complicate the use of self-created screensavers as true windows screensavers...
|
|
|
Post by Candle on Jul 5, 2004 11:12:01 GMT -5
I gave that a try but it didn't seem to work right ? it stop the movement but I had to hit esc to close the window .
|
|
|
Post by Candle on Jul 5, 2004 11:36:02 GMT -5
|
|
|
Post by AHBanen on Jul 5, 2004 12:06:09 GMT -5
Candle, You need to Create Standalone .exe using the options I gave! Otherwise - when you run the code from the editor - the code behaves as you experienced. The code worked - stopping the program on a move of the mouse - when the program is 'compiled' to an executable version, I know, I tested it before posting the code.
My impression is that the behaviour of END has changed since the posts you mention. At least when running code from the editor I see no difference in behaviour if I use END or not. In a compiled version the exe ended as expected (not pausing) when I set the options like I mentioned. So I think END has no longer effect, other then jumping to the end of the program (e.g. when used inside a loop).
So please create an exe and then report back if the code works or not (it should though). André
|
|
|
Post by Candle on Jul 5, 2004 12:17:43 GMT -5
I'm sorry I missed the close immediately part but when I changed it, it works fine . thank you for your help ..
|
|
|
Post by Candle on Jul 5, 2004 12:28:26 GMT -5
I guess I don't understand where the mouse part goes in the code as I can't get this to run ?
' Star field demo 1 ' ' This is also a bit of a tutorial on OpenGL and how Basic4GL does things. dim mouseXinit#, mouseYinit# mouseXinit# = Mouse_XD() mouseYinit# = Mouse_YD() while Mouse_XD() = MouseXinit# AND Mouse_YD() = MouseYinit# const maxStars = 200
dim stars#(maxStars)(2) ' Note: An array of maxStars 3D vectors. ' The # after it means floating point. Otherwise it would store integers (the default in Basic4GL)
dim i ' Note: ALL variables must be declared before use, with DIM
' Populate star field for i = 1 to maxStars stars#(i) = vec3 (rnd () % 201 - 100, rnd () % 201 - 100, -i) ' Vec3 creates a 3D vector. Parameters are X, Y and Z ' Rnd() returns a number between 0 and MAXINT (MAXINT = about 2 billion), ' So we use the % (mod) operator to convert it to a number between 0 and 200. ' We have to setup our vectors with respect to the coordinate system. ' In OpenGL, the coordinate system says that: ' X = How many units to the RIGHT. ' Y = How many units UP. ' Z = How many units OUT OF THE SCREEN. ' ' So because we want our stars to appear INTO the screen, we have to use a ' NEGATIVE Z value. next
glDisable (GL_DEPTH_TEST) ' This disables the Z buffer. ' (The Z buffer automatically determines which pixels are infront of the other ones. ' We don't need it for a star field though.)
' Main loop while true glClear (GL_COLOR_BUFFER_BIT) ' This clears the screen. ' The "colour buffer" refers to the actual image that we are going to draw. ' There are other buffers (like the Z buffer) that we could clear also if we ' were using them. But we're not :)
for i = 1 to maxStars ' Move the star forward, by adding 1 to Z stars#(i) = stars#(i) + vec3 (0, 0, 1)
' If the Z goes positive (infront of the screen), move it to the back again. if stars#(i)(2) >= 0 then stars#(i)(2) = -maxStars endif ' Note: All "if" statements must have an "endif", even if they are ' only on 1 line. ' Draw the star. ' In OpenGL you don't actually access the pixels directly. ' Instead you pass 3D data into OpenGL. It will do the 3D maths for you ' and draw the appropriate image on the screen. ' You place the 3D data between a glBegin() and a glEnd(). ' We want it to plot points (each point is a star), so we pass GL_POINTS ' to glBegin () glBegin (GL_POINTS) glVertex3fv (stars#(i)) ' This is a form of the glVertex command. ' The last 3 characters give us information about this particular ' version. ' 3 = Takes a 3D vector ' F = Floating point values ' V = Vector is passed in as an array glEnd () next SwapBuffers () ' Basic4GL uses "double buffered" mode. ' All drawing happens in the off-screen buffer. ' When we're finished, we "swap" it to the onscreen buffer by calling SwapBuffers()
WaitTimer (20) ' Wait timer slows us down. Parameter is the interval. ' Note: Frames per second (FPS) = 1000 / Interval ' ' So 1000 / 20 = 50 frames per second wend end
|
|
|
Post by AHBanen on Jul 5, 2004 12:55:40 GMT -5
The mouse code should replace the while true of the main loop. Like this: ' Star field demo 1 ' ' This is also a bit of a tutorial on OpenGL and how Basic4GL does things.
const maxStars = 200
dim stars#(maxStars)(2) ' Note: An array of maxStars 3D vectors. ' The # after it means floating point. Otherwise it would store integers (the default in Basic4GL)
dim i ' Note: ALL variables must be declared before use, with DIM
' Populate star field for i = 1 to maxStars stars#(i) = vec3 (rnd () % 201 - 100, rnd () % 201 - 100, -i) ' Vec3 creates a 3D vector. Parameters are X, Y and Z ' Rnd() returns a number between 0 and MAXINT (MAXINT = about 2 billion), ' So we use the % (mod) operator to convert it to a number between 0 and 200.
' We have to setup our vectors with respect to the coordinate system. ' In OpenGL, the coordinate system says that: ' X = How many units to the RIGHT. ' Y = How many units UP. ' Z = How many units OUT OF THE SCREEN. ' ' So because we want our stars to appear INTO the screen, we have to use a ' NEGATIVE Z value. next
glDisable (GL_DEPTH_TEST) ' This disables the Z buffer. ' (The Z buffer automatically determines which pixels are infront of the other ones. ' We don't need it for a star field though.)
' Main loop dim mouseXinit#, mouseYinit# mouseXinit# = Mouse_XD() mouseYinit# = Mouse_YD() while Mouse_XD() = MouseXinit# AND Mouse_YD() = MouseYinit# glClear (GL_COLOR_BUFFER_BIT) ' This clears the screen. ' The "colour buffer" refers to the actual image that we are going to draw. ' There are other buffers (like the Z buffer) that we could clear also if we ' were using them. But we're not :)
for i = 1 to maxStars
' Move the star forward, by adding 1 to Z stars#(i) = stars#(i) + vec3 (0, 0, 1)
' If the Z goes positive (infront of the screen), move it to the back again. if stars#(i)(2) >= 0 then stars#(i)(2) = -maxStars endif ' Note: All "if" statements must have an "endif", even if they are ' only on 1 line.
' Draw the star. ' In OpenGL you don't actually access the pixels directly. ' Instead you pass 3D data into OpenGL. It will do the 3D maths for you ' and draw the appropriate image on the screen.
' You place the 3D data between a glBegin() and a glEnd(). ' We want it to plot points (each point is a star), so we pass GL_POINTS ' to glBegin () glBegin (GL_POINTS) glVertex3fv (stars#(i)) ' This is a form of the glVertex command. ' The last 3 characters give us information about this particular ' version. ' 3 = Takes a 3D vector ' F = Floating point values ' V = Vector is passed in as an array glEnd () next
SwapBuffers () ' Basic4GL uses "double buffered" mode. ' All drawing happens in the off-screen buffer. ' When we're finished, we "swap" it to the onscreen buffer by calling SwapBuffers()
WaitTimer (20) ' Wait timer slows us down. Parameter is the interval. ' Note: Frames per second (FPS) = 1000 / Interval ' ' So 1000 / 20 = 50 frames per second wend end
Have fun making screensavers with Basic4GL (but try to understand the code first ) André
|
|
|
Post by Candle on Jul 5, 2004 13:06:36 GMT -5
Ok all try to learn more ;D. i do better when I can see how it is done .. thank you for the help .
|
|