Jump to content
  • Advertisement
Sign in to follow this  
wabbz111

mouse polygon drawing

This topic is 3788 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi i have a slight problem with this code.I is suppossed to draw a polygon with a mouse
#include <GL/glut.h>

GLdouble winHeight;


GLsizei winWidth =400, winheight=300;
GLint endPTCtr=0;

class scrPt{
      public:
      GLint x,y;
      };
      void init(void)
      {
           glClearColor (0.0, 0.0, 1.0,1.0);
           glMatrixMode(GL_PROJECTION);
           gluOrtho2D (0.0, 200.0, 0.0,150.0);
           }
           
           void displayFcn(void)
           {
                glClear(GL_COLOR_BUFFER_BIT);
                }
                
      void winReshapeFcn (GLint newWidth, GLint newHeight)
      {
           /*reset viewport parameters*/
           glViewport (0, 0, newWidth,newHeight);
           glMatrixMode(GL_PROJECTION);
           glLoadIdentity();
           gluOrtho2D (0.0, GLdouble (newWidth), 0.0, GLdouble (newHeight));
           
           /* reset dspaly window*/
           winWidth =  newWidth;
            winHeight = newHeight;
           }
           
      void drawLineSegment (scrPt endPt1,scrPt endPt2)
      {
           glBegin (GL_LINES);
           glVertex2i(endPt1.x, endPt1.y);
            glVertex2i(endPt2.x, endPt2.y);
          glEnd();
          }
          
          void polyline (GLint button, GLint action, GLint xMouse, GLint yMouse)
          {
               static scrPt endPt1, endPt2;
               int ptCtr;
               if(ptCtr == 0){
                if(button== GLUT_LEFT_BUTTON && action == GLUT_DOWN) {
                  endPt1.x= xMouse;
                  endPt1.y= (GLint)(winHeight - yMouse);
                  ptCtr = 1;
                  }
                  else
                     if (button == GLUT_RIGHT_BUTTON)
                         exit(0);
                    }
                    else
                      if(button == GLUT_LEFT_BUTTON && action == GLUT_DOWN){
                               endPt2.x = xMouse;
                               endPt2.x = (GLint)(winHeight- yMouse);
                               drawLineSegment (endPt1, endPt2);
                               
                               endPt1 = endPt2;
                               
                      }
                      else
                        if (button == GLUT_RIGHT_BUTTON)
                          exit(0);
                                   
                               glFlush();
                          }
                          
         int main (int argc, char** argv)
          {
               glutInit (&argc,argv);
               glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
               glutInitWindowPosition (100,100);
               glutInitWindowSize (winWidth,winHeight);
               glutCreateWindow ("draw");
               init();
               glutDisplayFunc(displayFcn);
               glutReshapeFunc(winReshapeFcn);
               glutMouseFunc(polyline);
               
          glutMainLoop();
          }
                       
                                                                  

the problem is with int ptCtr; if it i remove it from the code i get an error ptCtr undeclared.If i declare it i get two messages In function `int main(int, char**)': warning: passing `GLdouble' for converting 2 of `void glutInitWindowSize(int, int)' and if run it i get only a top window with no display area please help outNB: using devC++

Share this post


Link to post
Share on other sites
Advertisement
My guess is that you never learned C and want to start direct with OpenGL.. oh well.

Look at the top of the file where you have global variable declaration:
GLdouble winHeight;
GLsizei winWidth =400, winheight=300;

Now if you notice you have a winHeight who is a GLdouble(double), and winheight who is a GLsizei(int). The glutInitWindowSize function need two integer, so just erase the first one who is declared for nothing and it should work.

ptCtr have nothing to do with this, and it should be declared.

Share this post


Link to post
Share on other sites
thanks its drawing the display window now.However what should i declare PtCtr as? it still not drawing the right way.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!