OpenGL/GLUT 3D graphics question

Discussion in 'Mac Programming' started by kashmoney2006, Apr 20, 2008.

  1. kashmoney2006 macrumors regular

    Joined:
    Dec 12, 2007
    #1
    So I am writing an application that needs to be able to draw spheres and lines. I have written the UI using GLUT and GLUI. So what I need the program to be able to do is allow the user to be able to click on a sphere in the graphics window, click somewhere else on the graphics window and have it draw another sphere at the position of the second click and then draw a line (or small cylinder) connecting the two spheres. My question is, how do I draw a sphere at a certain position on the window? I know about glutWireSphere() and glutSolidSphere(), but I cant find a way to change to position of where the sphere is displayed (as the default is at the origin). Can somebody help me with this? Thanks
     
  2. laprej macrumors regular

    Joined:
    Oct 14, 2005
    Location:
    Troy, NY
    #2
    Look up glTranslate. This may be a bit of a steep learning curve if you're not really all that familiar with OpenGL...
     
  3. kashmoney2006 thread starter macrumors regular

    Joined:
    Dec 12, 2007
    #3
    yea im not familiar with OpenGL at all. I was hoping that there would be a drawsphere function that could input x, y, and z coordinates for the origin. is that too much to ask for? I guess if I had to, that translate function should work. but itll make me work alot harder. :(
     
  4. psingh01 macrumors 65816

    Joined:
    Apr 19, 2004
    #4
    It really isn't a lot of work. You are just calling one extra function :) If you imagine the glut method as drawing sphere at the origin, then glTranslate just moves it to some other part on the screen.
     
  5. kashmoney2006 thread starter macrumors regular

    Joined:
    Dec 12, 2007
    #5
    but the problem is i will need to move individual spheres, and gltranslate(), from what i can understand, moves the whole screen. thus it would move all the spheres on the screen. not just the one i want to move.
     
  6. kashmoney2006 thread starter macrumors regular

    Joined:
    Dec 12, 2007
    #6
    For some odd reason, now when I click on build and go, the application doesnt open? it still says "Skeleton modeler Launched" at the bottom of the xcode project window, but the application is not open. It never did this before, and I dont think I changed anything. Any reason why its not opening now? I can still double click on the .app file and open the application, but i dont get the output to the console that way. Any help?
     
  7. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #7
    This is why you use glMatrixPush() and glMatrixPop().
     
  8. kashmoney2006 thread starter macrumors regular

    Joined:
    Dec 12, 2007
    #8
    i see. I dont really understand what those do. but I guess ill try and look it up on google.
     
  9. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #9
    It is used to make changes to a matrix and then pop the matrix that you had before to the top of matrix stack I believe.
     
  10. Gelfin macrumors 68020

    Gelfin

    Joined:
    Sep 18, 2001
    Location:
    Denver, CO
    #10
    It's been years since I did any OpenGL, but one thing I do remember is this: Matrix operations are annoyingly counterintuitive to begin with, but you won't fully comprehend what you're doing in OpenGL until you grok them. Focus in that area until it makes sense, and you'll feel a lot less pain doing everything else.
     
  11. Animalk macrumors 6502

    Joined:
    May 27, 2007
    Location:
    Montreal Canada
    #11
    When i first started learning opengl, the hardest concept by far for me to understand was the pushing and popping of the 3 or 4 (don't remember them all) matrix types. Once that was grasped, the code just kept flowing.

    It's not as complicated as it first looks and it is important to always go back to basics. What is a stack, how does it work, what can i do with it, etc.

    Learning opengl is some of the most fun I have ever had coding though it is often quite frustrating. Good Luck :)
     
  12. psingh01 macrumors 65816

    Joined:
    Apr 19, 2004
    #12
    Here are great OpenGL tutorials: http://nehe.gamedev.net/

    You will have to learn the basics of OpenGL, it is not so simple of finding the right function that does what you want. OpenGL is a state machine, each function changes the state of the machine. So you have to have a better overall understanding on how the whole machine works instead of just picking things up function by function.

    As the previous poster said, once you get going you'll realize it is not all that complicated and actually quite simple the way it works.
     
  13. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #13
    I'd invest in a copy of the latest version of the Red Book if I were you (in fact I did :)).

    Leopard has OpenGL version 2.1 built in so you should be good to go.
     
  14. kashmoney2006 thread starter macrumors regular

    Joined:
    Dec 12, 2007
    #14
    Thanks I have come across those and they seem to be very informative. I think ill just have to keep reading and trying different things until i get a grasp on it. Thanks for all the help.
     

Share This Page