Oxygen Basic

Programming => Example Code => Topic started by: kryton9 on June 09, 2012, 12:16:07 PM

Title: freeglut CubeDemo3
Post by: kryton9 on June 09, 2012, 12:16:07 PM
A new cube demo worked out by Charles and me using the new freeglut library for Oxygen.
This has lighting, and movement. The titlebar has the instructions.

move in/out with the a and z key
rotate the cube with the arrow keys
esc to exit

fps is frames per second it is running at.
 
Unzip into your     oxygen\projects\   folder
Title: Re: freeglut CubeDemo3
Post by: Aurel on June 09, 2012, 12:29:58 PM
Hmm Kent ..it works but i think that is little bit slow comparing
with DirectX similiar program, i got 60fps
Title: Re: freeglut CubeDemo3
Post by: kryton9 on June 09, 2012, 12:41:58 PM
60 fps is not too bad Aurel, more than enough. I will work on something with more objects and textures for the next demo, we will see how it does. Thanks for trying it out. FPS is important so better to know.
On my netbook which is not too powerful I am getting around 300 fps.

Title: Re: freeglut CubeDemo3
Post by: Charles Pegge on June 09, 2012, 02:05:22 PM
Hi Kent,

To preserve aspect ration in freeglut (when the window is stretched):

Include this callback:

sub Reshape(sys w,h)
    establishProjectionMatrix w,h
end sub

then set up the callback as usual

        glutReshapeFunc    @reshape


They certainly make it painless

Charles

Title: Houston, we have a problem
Post by: kryton9 on June 09, 2012, 03:45:46 PM
I went to make the change Charles. My main programming is done on my small netbook. My notebook I save for gaming. The netbook has ATI video and the notebook NVidia.
I don't know what you guys saw when you ran the demo, but you should have seen a cube with different colors on each side that reacted to the lighting as it rotated around.

The same program on my notebook with NVidia just shows a purple cube with lighting.

First post will have the udpated version in a minute.

Title: Re: freeglut CubeDemo3
Post by: Charles Pegge on June 09, 2012, 04:12:02 PM
I'm using desktop NVidia - no glitches here,Kent. What happens to the other GLdemos that come with Oxygen?

I must shift into the dream dimension for a few hours, and trust I will not be abducted for medical experiments. Good Night :)

Charles
Title: Houston, problem solved
Post by: kryton9 on June 09, 2012, 04:37:15 PM
Stupid me, I keep forgetting my notebook has Optimus. It is intel video for general use and Nvidia for high end. It didn't switch to nvidia and was using the intel drivers. I manually forced it to use nvidia and problem solved. When you wrote that it worked on your nivida, that clicked in my memory about optimus headaches.

My recommendation, never buy Optimus or any other hybrid energy saving dual graphics solution like it.
Title: cube demo 4, a step back
Post by: kryton9 on June 09, 2012, 06:29:54 PM
I modified cube demo 3 to show a simpler way to handle keyboard input. Less code, but you lose multi-key at once input and also response speed.
But many times you don't need those features, so this is a simpler way to do things.

Just unzip into your existing oxygen/projects/cube demo 3     folder. 
Title: speed
Post by: kryton9 on June 09, 2012, 07:13:32 PM
I downloaded all the glut examples I could that were available for NeHe tutorials. Some of the advanced did take a while to load and run on my netbook. I don't think freeglut will be fast enough for games on weaker computers like my netbook. Also many of the examples had code relying on the underlying OS. I think that is why you see so many different downloads at the bottom of NeHe pages. I thought freeglut had it all and we would not need to go into the OS api.  I think worrying about cross platform is something I need to get over. Looking at the numbers, Windows is King and will be for some time.

Still for making quick tools and utilities, I think freeglut will be great.
Title: Re: freeglut CubeDemo3
Post by: JRS on June 09, 2012, 08:08:19 PM
Quote
Looking at the numbers, Windows is King and will be for some time.

The numbers ...

Title: Re: freeglut CubeDemo3
Post by: kryton9 on June 09, 2012, 09:56:27 PM
John, it is a possibility that can't be ruled out. That's why this upcoming Windows 8 debut is so important. If it turns out anything like Vista's introduction, then the doors are wide open again. But if it is a smooth experience as Windows 7 is, then they shall remain crowned King :)

Hardware manufacturers are announcing soon upcoming devices with Windows 8, so it is pretty close.

My dream device right now would be one device with cell phone capabilities in a 7" tablet form factor with slideout keyboard, that you can actually develop natively on, just as you can with netbooks now.
You would use headphone/mic or bluetooth headset for talking or speaker in quiet environment for the phone. So as long as the tablet is nearby you are set. Right now my tablet is 10", although I like the bigger screen, it does get tiresome holding for some time. I think the 7 to 8" probably is a good size.
Title: Re: freeglut CubeDemo3
Post by: Charles Pegge on June 09, 2012, 11:30:22 PM
Hi Kent,

I would hang onto to multikey, for instance: with arrow keys: press m to move up and down, r to rotate, z to move near and far, s to enlarge and reduce, l to control lighting.

Using materials:

Code: OxygenBasic
  1.  
  2.         glFloat ambient[4],diffuse[4],specular[4],shininess[1]
  3.         ambient <= 0.5, 0.1, 0.1, 1.0
  4.         diffuse <= 1.0, 0.1, 0.1, 1.0
  5.         specular<= 0.0, 0.0, 0.9, 1.0
  6.         shininess<=20.0
  7.         glMaterialfv GL_FRONT, GL_AMBIENT,   ambient
  8.         glMaterialfv GL_FRONT, GL_DIFFUSE,   diffuse
  9.         glMaterialfv GL_FRONT, GL_SPECULAR,  specular
  10.         glMaterialfv GL_FRONT, GL_SHININESS, shininess
  11.         '
  12.        GlutSolidSphere  1,36,16
  13.  

Material interacts with the light model:

Code: OxygenBasic
  1. GLfloat light_ambient[4]  = {0.2, 0.2, 0.2, 1}
  2. GLfloat light_diffuse[4]  = {0.7, 0.7, 0.7, 1}
  3. GLfloat light_specular[4] = {0.7, 0.7, 0.7, 1}
  4. GLfloat light_position[4] = {1.0, 1.0, 1.0, 0.0}
  5.  
Charles
Title: Re: freeglut CubeDemo3
Post by: kryton9 on June 09, 2012, 11:37:44 PM
Did you get some sleep. I can't believe you cranked out a nice demo so soon!  Thanks, looks nice.
Title: Re: freeglut CubeDemo3
Post by: Charles Pegge on June 09, 2012, 11:47:07 PM

Quote
Did you get some sleep

Yes, I think that is where my better ideas come from :)
Title: Re: freeglut CubeDemo3
Post by: Aurel on June 10, 2012, 12:59:06 AM
Of course that windows is king.. ;D
leave a linux where he belong - servers,experimental OS...etc
Linux is not a graphical OS and probably never will be...
Title: Re: freeglut CubeDemo3
Post by: Charles Pegge on June 12, 2012, 05:29:42 PM

Another FreeGlut Demo: using compiled drawing lists.

It will work in the /projects/FreeGlut folder

Code: OxygenBasic
  1.  
  2.     glNewList DrawingList 1, GL_COMPILE
  3.     '
  4.    GlutSolidSphere  1,36,16
  5.     '
  6.    glEndlist
  7.  
  8.  

Charles
Title: Re: freeglut CubeDemo3
Post by: kryton9 on June 12, 2012, 07:00:36 PM
Thanks Charles, another cool demo!  It is as cute as the Android green droid in a simpler way! My high school colors were blue and red, any reason why you like those colors?
Title: Re: freeglut CubeDemo3
Post by: Charles Pegge on June 13, 2012, 10:40:21 AM

I chose two contrasting colors Kent. Unlike school colors,  I think they need to be toned down for prolonged use though.

Two further demos: these use bothe the mouse and keyboard to move the object.
As before, they go in the projects/FreeGlut folder

Charles

Title: Re: freeglut CubeDemo3
Post by: kryton9 on June 13, 2012, 04:55:10 PM
Nice, works very smoothly with the mouse!