Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Graphics
  4. OpenGL- Tao- VB.Net simulating motion and zoom

OpenGL- Tao- VB.Net simulating motion and zoom

Scheduled Pinned Locked Moved Graphics
csharpgraphicsgame-devhelp
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    braveheartkenya
    wrote on last edited by
    #1

    Hi, I'm new to openGL programming. I'm trying to simulate motion and zooming in and out in an SimpleOpenGLControl from the Tao Framework. I've just begun trying to move an object up and down, but i can't seem to get the object to move. i know i'm missing something but i can't figure it out. I think it has to do with loading the transformed coordinates into a new buffer and displaying the contents from the buffer... but i don't know how to do that. Here's my code: Imports Tao.OpenGl Imports Tao.Platform Imports Tao.FreeGlut Public Class frmMainWin Dim xTrans, yTrans, zTrans As Single Private Sub frmMainWin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load myGlWindow.InitializeContexts() myGlWindow.AutoSwapBuffers = True 'init glwindow Gl.glClearColor(0.0F, 0.0F, 0.0F, 0.0F) 'Glu.gluLookAt( Gl.glViewport(0, 0, 400, 300) Gl.glMatrixMode(Gl.GL_PROJECTION) Gl.glLoadIdentity() Gl.glOrtho(0.0, 10.0, 0.0, 10.0, -10.0, 10.0) Gl.glMatrixMode(Gl.GL_MODELVIEW) Gl.glLoadIdentity() xTrans = 0 yTrans = 0 zTrans = 0 End Sub Private Sub myGlWindow_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles myGlWindow.Paint Gl.glClear(Gl.GL_COLOR_BUFFER_BIT) Gl.glColor3f(0.2F, 0.2F, 0.8F) 'Gl.glTranslatef(0.0F, 0.0F, 0.0F) Gl.glTranslatef(xTrans, yTrans, zTrans) Gl.glBegin(Gl.GL_TRIANGLES) 'Draw a triangle Gl.glVertex3f(0.5F, 1.0F, 0.0F) Gl.glVertex3f(0.0F, 0.0F, 0.0F) Gl.glVertex3f(1.0F, 0.0F, 0.0F) Gl.glEnd() End Sub Private Sub cmdUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUp.Click 'MsgBox("up") yTrans = yTrans + 1 myGlWindow.SwapBuffers() End Sub End Class Any help would be greatly appreciated. Thanks

    C 1 Reply Last reply
    0
    • B braveheartkenya

      Hi, I'm new to openGL programming. I'm trying to simulate motion and zooming in and out in an SimpleOpenGLControl from the Tao Framework. I've just begun trying to move an object up and down, but i can't seem to get the object to move. i know i'm missing something but i can't figure it out. I think it has to do with loading the transformed coordinates into a new buffer and displaying the contents from the buffer... but i don't know how to do that. Here's my code: Imports Tao.OpenGl Imports Tao.Platform Imports Tao.FreeGlut Public Class frmMainWin Dim xTrans, yTrans, zTrans As Single Private Sub frmMainWin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load myGlWindow.InitializeContexts() myGlWindow.AutoSwapBuffers = True 'init glwindow Gl.glClearColor(0.0F, 0.0F, 0.0F, 0.0F) 'Glu.gluLookAt( Gl.glViewport(0, 0, 400, 300) Gl.glMatrixMode(Gl.GL_PROJECTION) Gl.glLoadIdentity() Gl.glOrtho(0.0, 10.0, 0.0, 10.0, -10.0, 10.0) Gl.glMatrixMode(Gl.GL_MODELVIEW) Gl.glLoadIdentity() xTrans = 0 yTrans = 0 zTrans = 0 End Sub Private Sub myGlWindow_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles myGlWindow.Paint Gl.glClear(Gl.GL_COLOR_BUFFER_BIT) Gl.glColor3f(0.2F, 0.2F, 0.8F) 'Gl.glTranslatef(0.0F, 0.0F, 0.0F) Gl.glTranslatef(xTrans, yTrans, zTrans) Gl.glBegin(Gl.GL_TRIANGLES) 'Draw a triangle Gl.glVertex3f(0.5F, 1.0F, 0.0F) Gl.glVertex3f(0.0F, 0.0F, 0.0F) Gl.glVertex3f(1.0F, 0.0F, 0.0F) Gl.glEnd() End Sub Private Sub cmdUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUp.Click 'MsgBox("up") yTrans = yTrans + 1 myGlWindow.SwapBuffers() End Sub End Class Any help would be greatly appreciated. Thanks

      C Offline
      C Offline
      Christoph Menge
      wrote on last edited by
      #2

      Hi, do you invalidate the control somehow when changing yTrans? Otherwise, you won't notice any change. Check whether the Paint method is called at all using the debugger. EDIT: 2 more things: 1.) Handle the Resize-Event and do the following: Sorry, this is C#, but I don't really have an idea about VB. I guess this will help anyway: // Some private variable that stores initialization status. // Set this to true after InitializeContexts(); private bool initialized = false; protected override void OnResize(EventArgs e) { if (initialized) { MakeCurrent(); Gl.glViewport(0, 0, Width, Height); Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); Gl.glOrtho(0.0, 10.0, 0.0, 10.0, -10.0, 10.0); Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glLoadIdentity(); } } Also, make sure xTrans is not negative. Last, why do you call SwapBuffers(), although you set AutoSwapBuffers to true before? Hope this helps, Chris

      "Obstacles are those frightening things you see when you take your Eyes off your aim" - Henry Ford
      Articles  Blog

      modified on Sunday, February 24, 2008 4:35 PM

      B 1 Reply Last reply
      0
      • C Christoph Menge

        Hi, do you invalidate the control somehow when changing yTrans? Otherwise, you won't notice any change. Check whether the Paint method is called at all using the debugger. EDIT: 2 more things: 1.) Handle the Resize-Event and do the following: Sorry, this is C#, but I don't really have an idea about VB. I guess this will help anyway: // Some private variable that stores initialization status. // Set this to true after InitializeContexts(); private bool initialized = false; protected override void OnResize(EventArgs e) { if (initialized) { MakeCurrent(); Gl.glViewport(0, 0, Width, Height); Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); Gl.glOrtho(0.0, 10.0, 0.0, 10.0, -10.0, 10.0); Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glLoadIdentity(); } } Also, make sure xTrans is not negative. Last, why do you call SwapBuffers(), although you set AutoSwapBuffers to true before? Hope this helps, Chris

        "Obstacles are those frightening things you see when you take your Eyes off your aim" - Henry Ford
        Articles  Blog

        modified on Sunday, February 24, 2008 4:35 PM

        B Offline
        B Offline
        braveheartkenya
        wrote on last edited by
        #3

        Thanks for the information. I'll handle the resize event in a few. Just checking...Is there any fault in not handling it? What do you mean by "invalidate the control?" About the swapping buffers issue... i was working with trial and error to try and see why my code wasnt working...thats why both are there (by mistake). I've removed the swapbuffers() fn now. The solution to my problem i found was to clear the buffer and do 'myGlWindow.refresh' just after the transformation calculations. Don't know why it worked...may be you could explain it to me...

        C 1 Reply Last reply
        0
        • B braveheartkenya

          Thanks for the information. I'll handle the resize event in a few. Just checking...Is there any fault in not handling it? What do you mean by "invalidate the control?" About the swapping buffers issue... i was working with trial and error to try and see why my code wasnt working...thats why both are there (by mistake). I've removed the swapbuffers() fn now. The solution to my problem i found was to clear the buffer and do 'myGlWindow.refresh' just after the transformation calculations. Don't know why it worked...may be you could explain it to me...

          C Offline
          C Offline
          Christoph Menge
          wrote on last edited by
          #4

          As long as your window cannot be resized, you do not really have to handle the resize event, that is true. However, as it is basically no more code (because you can just move most of your inialization code into it), I consider it better. When a control is invalidated, you force the control and its children to redraw. The Invalidate()-method and the Refresh()-method do exactly that (only the latter also forces immediate redraw). Both methods are implemented by Control. However, Tao's SimpleOpenGlControl also offers a Draw()-method. It's implementation is rather simple: public void Draw() { this.Invalidate(); } So it is essentially all the same thing! I suggest, however, to use the Draw()-method because future releases of the control might behave differently.

          "Obstacles are those frightening things you see when you take your Eyes off your aim" - Henry Ford
          Articles  Blog

          B 1 Reply Last reply
          0
          • C Christoph Menge

            As long as your window cannot be resized, you do not really have to handle the resize event, that is true. However, as it is basically no more code (because you can just move most of your inialization code into it), I consider it better. When a control is invalidated, you force the control and its children to redraw. The Invalidate()-method and the Refresh()-method do exactly that (only the latter also forces immediate redraw). Both methods are implemented by Control. However, Tao's SimpleOpenGlControl also offers a Draw()-method. It's implementation is rather simple: public void Draw() { this.Invalidate(); } So it is essentially all the same thing! I suggest, however, to use the Draw()-method because future releases of the control might behave differently.

            "Obstacles are those frightening things you see when you take your Eyes off your aim" - Henry Ford
            Articles  Blog

            B Offline
            B Offline
            braveheartkenya
            wrote on last edited by
            #5

            Thanks for the information. iv;e taken it into consideration and now i'm using the Draw() method ... and handling resizing. Now i have another problem, which i think is related, coz i'm convinced that there's fundamentally something wrong with my code. Let me try explain it. I have objects drawn into the SimpleOpenGL control onClick of different buttons, but the problem is everytime i click on a button to draw (add) a new object... the previous one disappears. might you know what the problem is? Then another thing. I'd like to put text into the control. Could you point me in the right direction to do this. I read some other guys post about doing it in C# (somewhere near this one)... but i couldnt find some GDITexFont function or sth like that. Your help is highly valued and appreciated.

            C 1 Reply Last reply
            0
            • B braveheartkenya

              Thanks for the information. iv;e taken it into consideration and now i'm using the Draw() method ... and handling resizing. Now i have another problem, which i think is related, coz i'm convinced that there's fundamentally something wrong with my code. Let me try explain it. I have objects drawn into the SimpleOpenGL control onClick of different buttons, but the problem is everytime i click on a button to draw (add) a new object... the previous one disappears. might you know what the problem is? Then another thing. I'd like to put text into the control. Could you point me in the right direction to do this. I read some other guys post about doing it in C# (somewhere near this one)... but i couldnt find some GDITexFont function or sth like that. Your help is highly valued and appreciated.

              C Offline
              C Offline
              Christoph Menge
              wrote on last edited by
              #6

              Hi, from what you say I guess you don't really have a rendering-loop. See, your OpenGL image is drawn this way: 1. Clear screen (glClear(), etc.) 2. Draw allvisible objects in a certain order (lots of code) 3. Wait until OpenGL finished drawing (glFlush()) 4. Swap front/back buffer to make the newly drawn objects visible (SwapBuffers()) So you have to remember a list of objects you want to draw. When one of your buttons is clicked, it should do sth like that: myRenderList.Add(someObject); myOpenGLControl.Invalidate(); Note: Do NOT put any OpenGL commands in a button. You should have one and only one loop to do all the GL stuff! Managing scene information (all objects, how to describe them, whether they are visible, etc.) is the hard part - the OpenGL commands are comparatively simple. (See the term 'scene graph' for more on that). For text rendering, check NeHe's tutorial[^]. He presents three options. You might want to take a look at EaseSDK[^] to make things easier. It includes CeGUI, which supports not only text rendering, but real GUI elements such as buttons, scroll bars, etc. Regards, Chris

              "Obstacles are those frightening things you see when you take your Eyes off your aim" - Henry Ford
              Articles  Blog

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups