示例#1
0
文件: lab2.cpp 项目: Tampy/CS537
// OpenGL initialization
void
init()
{
	srand(time(NULL));

	numSquares = 0;

	drawSquares(0, 0, 1, 1, 4, 4);

	exitMaker();

    // Create and initialize a buffer object

   // Load shaders and use the resulting shader program
    GLuint program = InitShader( "vshader00_v110.glsl", "fshader00_v110.glsl" );
    glUseProgram( program );

    
    vPosition = glGetAttribLocation( program, "vPosition" );
	
    glEnableVertexAttribArray( vPosition );
    
	
	color_loc = glGetUniformLocation(program, "color");
	model_view_loc = glGetUniformLocation(program, "modelview");

    glEnable( GL_DEPTH_TEST );
    glClearColor( 1.0, 1.0, 1.0, 1.0 ); 
}
示例#2
0
void pickSquares(int button, int state, int x, int y)
{
   GLuint selectBuf[BUFSIZE];
   GLint hits;
   GLint viewport[4];

   if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN)
      return;

   glGetIntegerv (GL_VIEWPORT, viewport);

   glSelectBuffer (BUFSIZE, selectBuf);
   (void) glRenderMode (GL_SELECT);

   glInitNames();
   glPushName(0);

   glMatrixMode (GL_PROJECTION);
   glPushMatrix ();
   glLoadIdentity ();
/*  create 5x5 pixel picking region near cursor location	*/
   gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y), 
                  5.0, 5.0, viewport);
   gluOrtho2D (0.0, 3.0, 0.0, 3.0);
  
   drawSquares (GL_SELECT);

   glMatrixMode (GL_PROJECTION);
   glPopMatrix ();
   glFlush ();

   hits = glRenderMode (GL_RENDER);
   processHits (hits, selectBuf);
   glutPostRedisplay();
} 
int main5 (int argc, char** argv)
{
	char* filename;
	int c;

	// create memory storage that will contain all the dynamic data
	gStorage = cvCreateMemStorage(0);

    if(argc == 2 ) {
        filename = argv[1];
    } else {
        printf("Usage:\t%s image_file\n", argv[0]);
        printf("\timage_file: image that maybe contains rectangle\n\n");
        return 0;
    }

	gImg0 = cvLoadImage(filename, 1);
	if (!gImg0)
	{
		printf("Couldn't load %s\n", filename);
		return 0;
	}
	gImg = cvCloneImage(gImg0);

	// create window and a trackbar (slider) with parent "image" and set callback
	// (the slider regulates upper threshold, passed to Canny edge detector)
	cvNamedWindow(wndname, 1);
	if (gImg) {
		CvSeq* squares = findSquares4(gImg, gStorage);
		drawSquares(gImg, squares);
	}

//	cvCreateTrackbar("canny thresh", wndname, &thresh, 1000, on_trackbar);
//
//	// force the image processing
//	on_trackbar(0);

	// release both images
	cvReleaseImage(&gImg);
	cvReleaseImage(&gImg0);

	// clear memory storage - reset free space position
	cvClearMemStorage(gStorage);

    for(;;)
	{
    	// wait for key.
    	// Also the function cvWaitKey takes care of event processing
    	c = cvWaitKey(0);

    	if (c == 27)
    		break;
	}

	cvDestroyWindow(wndname);

	return 0;
}
void on_trackbar(CvPoint& centre, IplImage* img,CvMemStorage* &storage1)  
{  
	if( img )  {
		drawSquares( img, 
			findSquares4( img, storage1,true ) ,
			centre);
		cvReleaseMemStorage(&storage1 ); 
	}
	else cout<<"error in trackbar"<<endl;
}  
示例#5
0
bool Sample_13_3::sendMessage(int message, int mode, int x, int y)
{
	GLuint selectBuf[BUFSIZE];
	GLint hits;
	GLint viewport[4];

	switch (message) {
	case SDL_BUTTON_LEFT:
		/*  sets up selection mode, name stack,
		 *  and projection matrix for picking.  Then the
		 *  objects are drawn.
		 */
		if (mode==SDL_PRESSED) {
			glGetIntegerv (GL_VIEWPORT, viewport);

			glSelectBuffer (BUFSIZE, selectBuf);
			(void) glRenderMode (GL_SELECT);

			glInitNames();
			glPushName(0);

			glMatrixMode (GL_PROJECTION);
			glPushMatrix ();
			glLoadIdentity ();
			/*  create 5x5 pixel picking region near cursor location	*/
			gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y),
					5.0, 5.0, viewport);
			gluOrtho2D (0.0, 3.0, 0.0, 3.0);
			drawSquares (GL_SELECT);

			glMatrixMode (GL_PROJECTION);
			glPopMatrix ();

			hits = glRenderMode (GL_RENDER);
			processHits (hits, selectBuf);
		}
		break;
	default:
		return false;
		break;
	}

	return true;
}
示例#6
0
void switchShape(int shape){
  switch ( shape ) 
  {
    case 0:        
      drawTriangles();  
      break;

    case 1:
      drawSquares();
      break;

    case 2:
      drawStar();
      break;

    default:
      break;
  }
}
示例#7
0
int main(int argc, char** argv)
{
    int i, c;
    // create memory storage that will contain all the dynamic data
    storage = cvCreateMemStorage(0);

    for( i = 0; names[i] != 0; i++ )
    {
        // load i-th image
        img0 = cvLoadImage( names[i], 1 );
        if( !img0 )
        {
            printf("Couldn't load %s\n", names[i] );
            continue;
        }
        img = cvCloneImage( img0 );

        // create window and a trackbar (slider) with parent "image" and set callback
        // (the slider regulates upper threshold, passed to Canny edge detector)
        cvNamedWindow( wndname, 1 );

        // find and draw the squares
        drawSquares( img, findSquares4( img, storage ) );

        // wait for key.
        // Also the function cvWaitKey takes care of event processing
        c = cvWaitKey(0);
        // release both images
        cvReleaseImage( &img );
        cvReleaseImage( &img0 );
        // clear memory storage - reset free space position
        cvClearMemStorage( storage );
        if( (char)c == 27 )
            break;
    }

    cvDestroyWindow( wndname );

    return 0;
}
int main(int argc, char** argv){
  int pressed_key;
  IplImage *img = NULL, *img_gray = NULL;
  CvMemStorage* storage = NULL;

  // create memory storage that will contain all the dynamic data
  storage = cvCreateMemStorage(0);

  for( int i = 1; i < argc; i++ ){
    if( (img = cvLoadImage( argv[i], CV_LOAD_IMAGE_COLOR )) == 0 ){
      printf("Couldn't load %s\n", argv[i] );
      continue;
    }

    // convert input image to grayscale
    img_gray = cvCreateImage(cvGetSize( img ), IPL_DEPTH_8U, CHANNELS_GRAY);
    cvCvtColor( img, img_gray, CV_BGR2GRAY );

    // find all squares
    CvSeq* squares = cvFindPlateCandidates( img, storage );
    CvSeq* unified = cvCombineContours(squares, storage);
    CvSeq* plates  = cvPlateSegmentation( img_gray, unified, storage );

    // draw all squares
    drawSquares( img, unified );
    pressed_key = cvWaitKey();

    // release images, clear memory storage
    cvReleaseImage( &img );
    cvReleaseImage( &img_gray );
    cvClearMemStorage( storage );

    if( (char)pressed_key == ESC )
      break;
  }

  return 0;
}
示例#9
0
void EyeTracker::startTracker()
{
	while(true)
	{
		captureEyeFrame();
		captureSceneFrame();

		Point2f p = doTrack();

		//qDebug() << "x: " << p.x << " y: " << p.y;
		
		drawTrasholds();
		drawSquares(findSquares());
		
		cvShowImage(PUPIL_DETECTION_WINDOW_NAME, grayEyeImagePts);

		releaseGrayEyeImage();
		releaseGraySceneImage();

		int k = cvWaitKey(20);
	
		if( k == 27 )
			break;
	/*
		if( k == 'w' || k == 'W' )
			++highThreshold;
	
		else if ( k == 's' || k == 'S' )
			--highThreshold;
	
		else if( k == 'q' || k == 'Q' )
			++squareThreshold;
	
		else if ( k == 'a' || k == 'A' )
			--squareThreshold;*/
	}
}
void Picksquare::mousePressEvent(QMouseEvent *e)

{
   GLuint selectBuf[BUFSIZE];
   GLint hits;
   GLint viewport[4];

   if (e-> button() != LeftButton) //|| state != GLUT_DOWN)
      return;

   glGetIntegerv (GL_VIEWPORT, viewport);

   glSelectBuffer (BUFSIZE, selectBuf);
   (void) glRenderMode (GL_SELECT);

   glInitNames();
   glPushName(0);

   glMatrixMode (GL_PROJECTION);
   glPushMatrix ();
   glLoadIdentity ();

//  create 5x5 pixel picking region near cursor location        

   gluPickMatrix ((GLdouble) e->x(), (GLdouble) (viewport[3] - e->y()), 
                  5.0, 5.0, viewport);
   gluOrtho2D (0.0, 3.0, 0.0, 3.0);
   drawSquares (GL_SELECT);

   glMatrixMode (GL_PROJECTION);
   glPopMatrix ();
   glFlush ();

   hits = glRenderMode (GL_RENDER);
   processHits (hits, selectBuf);
   update();
} 
示例#11
0
void display(void)
{
   glClear(GL_COLOR_BUFFER_BIT);
   drawSquares (GL_RENDER);
   glFlush();
}
void Picksquare::paintGL(void)
{
   glClear(GL_COLOR_BUFFER_BIT);
   drawSquares (GL_RENDER);
   glFlush();
}
void GraphicsEngine::drawBoard()
{
	drawBackground();
	drawSquares();

}
void on_trackbar( int a ) 
{  
	if( img )  
		drawSquares( img, findSquares4( img, storage ) );
} 
示例#15
0
static void testmode(int mode)
{
    int xmax, ymax, i, x, y, yw, ys, c;
    vga_modeinfo *modeinfo;

    vga_setmode(mode);

    modeinfo = vga_getmodeinfo(mode);

    printf("Width: %d  Height: %d  Colors: %d\n",
           modeinfo->width,
           modeinfo->height,
           modeinfo->colors);
    printf("DisplayStartRange: %xh  Maxpixels: %d  Blit: %s\n",
           modeinfo->startaddressrange,
           modeinfo->maxpixels,
           modeinfo->haveblit ? "YES" : "NO");

#ifdef TEST_MODEX
    if (modeinfo->colors == 256)
        printf("Switching to ModeX ... %s\n",
               (vga_setmodeX()? "done" : "failed"));
#endif

    vga_screenoff();

    xmax = vga_getxdim() - 1;
    ymax = vga_getydim() - 1;

    vga_setcolor(vga_white());
    vga_drawline(0, 0, xmax, 0);
    vga_drawline(xmax, 0, xmax, ymax);
    vga_drawline(xmax, ymax, 0, ymax);
    vga_drawline(0, ymax, 0, 0);

    /* Draw crosses */
    for (i = 0; i <= 15; i++) {
        vga_setegacolor(i);
        vga_drawline(10 + i * 5, 10, 89 + i * 5, 89);
    }
    for (i = 0; i <= 15; i++) {
        vga_setegacolor(i);
        vga_drawline(89 + i * 5, 10, 10 + i * 5, 89);
    }

    vga_screenon();

    ys = 100;
    yw = (ymax - 100) / 4;
    switch (vga_getcolors()) {
    case 256:
        /* Draw horizontal color bands using palette */
        for (i = 0; i < 60; ++i) {
            c = (i * 64) / 60;
            vga_setpalette(i + 16, c, c, c);
            vga_setpalette(i + 16 + 60, c, 0, 0);
            vga_setpalette(i + 16 + (2 * 60), 0, c, 0);
            vga_setpalette(i + 16 + (3 * 60), 0, 0, c);
        }
        line[0] = line[xmax] = 15;
        line[1] = line[xmax - 1] = 0;
        for (x = 2; x < xmax - 1; ++x)
            line[x] = (((x - 2) * 60) / (xmax - 3)) + 16;
        for (y = ys; y < ys + yw; ++y)	/* gray */
            vga_drawscanline(y, line);
        for (x = 2; x < xmax - 1; ++x)
            line[x] += 60;
        ys += yw;
        for (y = ys; y < ys + yw; ++y)	/* red */
            vga_drawscanline(y, line);
        for (x = 2; x < xmax - 1; ++x)
            line[x] += 60;
        ys += yw;
        for (y = ys; y < ys + yw; ++y)	/* green */
            vga_drawscanline(y, line);
        for (x = 2; x < xmax - 1; ++x)
            line[x] += 60;
        ys += yw;
        for (y = ys; y < ys + yw; ++y)	/* blue */
            vga_drawscanline(y, line);
        break;

    case 1 << 15:
    case 1 << 16:
    case 1 << 24:
        /* Draw horizontal color bands in RGB */
        for (x = 2; x < xmax - 1; ++x) {
            c = ((x - 2) * 255) / (xmax - 4);
            y = ys;
            vga_setrgbcolor(c, c, c);
            vga_drawline(x, y, x, y + yw - 1);
            y += yw;
            vga_setrgbcolor(c, 0, 0);
            vga_drawline(x, y, x, y + yw - 1);
            y += yw;
            vga_setrgbcolor(0, c, 0);
            vga_drawline(x, y, x, y + yw - 1);
            y += yw;
            vga_setrgbcolor(0, 0, c);
            vga_drawline(x, y, x, y + yw - 1);
        }
        drawSquares(xmax, ymax);
        break;
    default:
        /* Draw vertical color bars */
        if (vga_getcolors() == 16) {
            for (i = 0; i < xmax - 1; i++)
                line[i] = (i + 2) % 16;
            line[0] = line[xmax] = 15;
            line[1] = line[xmax - 1] = 0;
        }
        if (vga_getcolors() == 2) {
            for (i = 0; i <= xmax; i++)
                line[i] = 0x11;
            line[0] = 0x91;
        }
        for (i = 100; i < ymax - 1; i++)
            vga_drawscanline(i, line);
        break;

    }

    if (getchar() == 'd')
        vga_dumpregs();

}
示例#16
0
void Sample_13_3::draw()
{
	glClear(GL_COLOR_BUFFER_BIT);
	drawSquares (GL_RENDER);
}