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. C / C++ / MFC
  4. OnMouseMove swap and clear problem

OnMouseMove swap and clear problem

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpgame-devtutorial
4 Posts 3 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.
  • M Offline
    M Offline
    Member 3375334
    wrote on last edited by
    #1

    Hello, i need help with this onMouseMove function... what i am doing here is drawing a line on the left and right side. On the left it;s all OpenGL AVI on the right i am calling my own function to draw the same lines as i move a mouse... however my problem is with MakeCurrent and clear screen here... because when i draw a line and rotate it ... there are bunch of lines all around. I don't know what i am doing wrong and where i need this swap buffer.... can someone please tell me how to get rid of those multiple lines when i move my mouse:

    void CtestopenglView::OnMouseMove(UINT nFlags, CPoint point)
    {
    // TODO: Add your message handler code here and/or call default
    wglMakeCurrent(m_hDC,m_hRC);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glClear(GL_COLOR_BUFFER_BIT);
    ::SwapBuffers(m_hDC);
    if(m_drawenabled)
    {
    m_start = point;
    glPushMatrix();
    glColor3f(0.0,0.0,0.0);
    DrawLine(m_start.x+300, m_start.y, m_end.x+300, m_end.y);

    	glBegin(GL\_LINES);
    	glVertex3d(m\_start.x, m\_start.y,0);
    	glVertex3d(m\_end.x, m\_end.y,0);
    	glEnd();
    	glPopMatrix();
    
    	m\_start = point;
    	glPushMatrix();
    	glColor3f(1.0,1.0,1.0);
    	DrawLine(m\_start.x+300, m\_start.y, m\_end.x+300, m\_end.y);
    	
    	glBegin(GL\_LINES);
    	glVertex3d(m\_start.x, m\_start.y,0);
    	glVertex3d(m\_end.x, m\_end.y,0);
    	glEnd();
    	glPopMatrix();
    }
    CView::OnMouseMove(nFlags, point);
    wglMakeCurrent(m\_hDC,NULL);
    wglMakeCurrent(m\_hDC,m\_hRC);
    glFlush();
    ::SwapBuffers(m\_hDC);
    

    }

    thanks

    S C 2 Replies Last reply
    0
    • M Member 3375334

      Hello, i need help with this onMouseMove function... what i am doing here is drawing a line on the left and right side. On the left it;s all OpenGL AVI on the right i am calling my own function to draw the same lines as i move a mouse... however my problem is with MakeCurrent and clear screen here... because when i draw a line and rotate it ... there are bunch of lines all around. I don't know what i am doing wrong and where i need this swap buffer.... can someone please tell me how to get rid of those multiple lines when i move my mouse:

      void CtestopenglView::OnMouseMove(UINT nFlags, CPoint point)
      {
      // TODO: Add your message handler code here and/or call default
      wglMakeCurrent(m_hDC,m_hRC);
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
      glClear(GL_COLOR_BUFFER_BIT);
      ::SwapBuffers(m_hDC);
      if(m_drawenabled)
      {
      m_start = point;
      glPushMatrix();
      glColor3f(0.0,0.0,0.0);
      DrawLine(m_start.x+300, m_start.y, m_end.x+300, m_end.y);

      	glBegin(GL\_LINES);
      	glVertex3d(m\_start.x, m\_start.y,0);
      	glVertex3d(m\_end.x, m\_end.y,0);
      	glEnd();
      	glPopMatrix();
      
      	m\_start = point;
      	glPushMatrix();
      	glColor3f(1.0,1.0,1.0);
      	DrawLine(m\_start.x+300, m\_start.y, m\_end.x+300, m\_end.y);
      	
      	glBegin(GL\_LINES);
      	glVertex3d(m\_start.x, m\_start.y,0);
      	glVertex3d(m\_end.x, m\_end.y,0);
      	glEnd();
      	glPopMatrix();
      }
      CView::OnMouseMove(nFlags, point);
      wglMakeCurrent(m\_hDC,NULL);
      wglMakeCurrent(m\_hDC,m\_hRC);
      glFlush();
      ::SwapBuffers(m\_hDC);
      

      }

      thanks

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      What happens if you get rid of the first SwapBuffers call? I have a feeling that the glClear won't be clearing the buffer you're drawing on, and also that you only need one SwapBuffer call per iteration (you'll be drawing on the back buffer and swapping it to the front once it's drawn on?, then doing the same thing with the other buffer at the next iteration)

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      M 1 Reply Last reply
      0
      • S Stuart Dootson

        What happens if you get rid of the first SwapBuffers call? I have a feeling that the glClear won't be clearing the buffer you're drawing on, and also that you only need one SwapBuffer call per iteration (you'll be drawing on the back buffer and swapping it to the front once it's drawn on?, then doing the same thing with the other buffer at the next iteration)

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        M Offline
        M Offline
        Member 3375334
        wrote on last edited by
        #3

        hey, if i take out the first swap only i do get one line on the screen ... however it does not stay on the screen when i try to draw another... it dissapears... i need to keep on drawing the lines and keep on the screen...so that i could write something like WE right now after taking that swap out and trying to draw second line of the W first line is no longer on the screen... what should i do

        1 Reply Last reply
        0
        • M Member 3375334

          Hello, i need help with this onMouseMove function... what i am doing here is drawing a line on the left and right side. On the left it;s all OpenGL AVI on the right i am calling my own function to draw the same lines as i move a mouse... however my problem is with MakeCurrent and clear screen here... because when i draw a line and rotate it ... there are bunch of lines all around. I don't know what i am doing wrong and where i need this swap buffer.... can someone please tell me how to get rid of those multiple lines when i move my mouse:

          void CtestopenglView::OnMouseMove(UINT nFlags, CPoint point)
          {
          // TODO: Add your message handler code here and/or call default
          wglMakeCurrent(m_hDC,m_hRC);
          glMatrixMode(GL_MODELVIEW);
          glLoadIdentity();
          glClear(GL_COLOR_BUFFER_BIT);
          ::SwapBuffers(m_hDC);
          if(m_drawenabled)
          {
          m_start = point;
          glPushMatrix();
          glColor3f(0.0,0.0,0.0);
          DrawLine(m_start.x+300, m_start.y, m_end.x+300, m_end.y);

          	glBegin(GL\_LINES);
          	glVertex3d(m\_start.x, m\_start.y,0);
          	glVertex3d(m\_end.x, m\_end.y,0);
          	glEnd();
          	glPopMatrix();
          
          	m\_start = point;
          	glPushMatrix();
          	glColor3f(1.0,1.0,1.0);
          	DrawLine(m\_start.x+300, m\_start.y, m\_end.x+300, m\_end.y);
          	
          	glBegin(GL\_LINES);
          	glVertex3d(m\_start.x, m\_start.y,0);
          	glVertex3d(m\_end.x, m\_end.y,0);
          	glEnd();
          	glPopMatrix();
          }
          CView::OnMouseMove(nFlags, point);
          wglMakeCurrent(m\_hDC,NULL);
          wglMakeCurrent(m\_hDC,m\_hRC);
          glFlush();
          ::SwapBuffers(m\_hDC);
          

          }

          thanks

          C Offline
          C Offline
          cmk
          wrote on last edited by
          #4

          For msg based painting you should only draw in the paint handler. In the mouse handler save any mouse specific state that's important then invalidate the area that needs to be redrawn.

          ...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack

          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