Real Software Forums
http://forums.realsoftware.com/

OpenGL and SpriteSurface Help
http://forums.realsoftware.com/viewtopic.php?f=4&t=43490
Page 1 of 1

Author:  NaNdummy [ Thu Apr 05, 2012 2:44 pm ]
Post subject:  OpenGL and SpriteSurface Help

Hi

I am a programmer and developed some games with Real Studio. But however - I never used OpenGL or SuperSpriteSurface. So could please someone help me:

1. To build with OpenGL: A small white ball and a blue one which moves in a circla around the white one (in 3D)
2. To build with SuperSpriteSurface: A small character which can run and jump. There are low walls which can be jumped over (in 2D)

Regards
NaNdummy

Btw, you do not have to describe me any method, I am not a newbie.

Author:  jquan [ Fri Apr 06, 2012 1:33 pm ]
Post subject:  Re: OpenGL and SpriteSurface Help

For 1, the simplest way I can think of (off the top of my head, so do test):

Create a declare to gluSphere (should be standard on Mac; need glu32.dll on Win) and use it to create your two spheres.

For drawing in pseudocode:
OpenGL.glLoadIdentity // Reset transformations

// White sphere first
OpenGL.glTranslatef(x,y,z) // position
OpenGL.glColor3f(1, 1, 1) // white color
declare gluSphere(handle, radius, slices, stacks) // draw sphere

// Blue sphere next
OpenGL.glTranslatef(x,y,z) // orbit distance from white sphere, keep this constant or you'll affect rotation
OpenGL.glRotatef(angle,x,y,z) // angle and axis (your axis is probably 0,1,0 if orbiting around Y)
OpenGL.glColor3f(0, 0, 1) // blue color
declare gluSphere(handle, radius, slices, stacks)

The key is that the translate and rotate functions are relative. First, Reset everything with LoadIdentity so that subsequent translates don't build on the last. The first translate sets the white sphere's position, but the second translate for the blue one is an offset from the last translation. The rotate is then considered absolute: you must keep track of the angle yourself. It's easy to mess up here, so hopefully I've written the code correctly myself!

You could put all of this code into OpenGLSurface.Render and have a timer keep calling the Render method.


Regards,

Jeff Quan
jeff@jcquan.com
http://www.jcquan.com/JQportfolio
My RBGL replacement classes: http://www.jcquan.com/REALbasic

Author:  NaNdummy [ Sat Apr 07, 2012 5:51 am ]
Post subject:  Re: OpenGL and SpriteSurface Help

Thanks! That helped much!!!

Now for #2...

Author:  mauitom [ Sat Apr 07, 2012 8:38 pm ]
Post subject:  Re: OpenGL and SpriteSurface Help

The OpenGL Redbook had a demo with spinning planets that you should check out. Scroll down on this page and look for "planet". I duplicated this project a million years ago in Rb. Don't have it anymore, but if you read thru the code, you should be able to get things rolling. You'll probably need to add some GLUT declares on your own. Have fun ... 8)

http://lab.bachem-it.com/opengl/redbook/

Author:  NaNdummy [ Sun Apr 08, 2012 8:37 am ]
Post subject:  Re: OpenGL and SpriteSurface Help

Thanks mauitom! Looks very interesting.

Author:  NaNdummy [ Sun Apr 08, 2012 10:04 am ]
Post subject:  Re: OpenGL and SpriteSurface Help

jquan wrote:
For 1, the simplest way I can think of (off the top of my head, so do test):

Create a declare to gluSphere (should be standard on Mac; need glu32.dll on Win) and use it to create your two spheres.

For drawing in pseudocode:
OpenGL.glLoadIdentity // Reset transformations

// White sphere first
OpenGL.glTranslatef(x,y,z) // position
OpenGL.glColor3f(1, 1, 1) // white color
declare gluSphere(handle, radius, slices, stacks) // draw sphere

// Blue sphere next
OpenGL.glTranslatef(x,y,z) // orbit distance from white sphere, keep this constant or you'll affect rotation
OpenGL.glRotatef(angle,x,y,z) // angle and axis (your axis is probably 0,1,0 if orbiting around Y)
OpenGL.glColor3f(0, 0, 1) // blue color
declare gluSphere(handle, radius, slices, stacks)

The key is that the translate and rotate functions are relative. First, Reset everything with LoadIdentity so that subsequent translates don't build on the last. The first translate sets the white sphere's position, but the second translate for the blue one is an offset from the last translation. The rotate is then considered absolute: you must keep track of the angle yourself. It's easy to mess up here, so hopefully I've written the code correctly myself!

You could put all of this code into OpenGLSurface.Render and have a timer keep calling the Render method.


Regards,

Jeff Quan
jeff@jcquan.com
http://www.jcquan.com/JQportfolio
My RBGL replacement classes: http://www.jcquan.com/REALbasic


Hmm... the declares throw a syntax error...

Author:  mauitom [ Sun Apr 08, 2012 9:11 pm ]
Post subject:  Re: OpenGL and SpriteSurface Help

Had a few minutes, here you go, a demo! :D

http://bigdaddysurf.com/blog/?p=499

Image

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/