Пример #1
0
void display(void)
{
   int i;
   GLushort values[HISTOGRAM_SIZE][3];
   
   glClear(GL_COLOR_BUFFER_BIT);
   glRasterPos2i(1, 1);
   glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
   
   glGetHistogram(GL_HISTOGRAM, GL_TRUE, GL_RGB, GL_UNSIGNED_SHORT, values);

   /* Plot histogram */
   
   glBegin(GL_LINE_STRIP);
   glColor3f(1.0, 0.0, 0.0);
   for ( i = 0; i < HISTOGRAM_SIZE; i++ )
       glVertex2s(i, values[i][0]);
   glEnd();

   glBegin(GL_LINE_STRIP);
   glColor3f(0.0, 1.0, 0.0);
   for ( i = 0; i < HISTOGRAM_SIZE; i++ )
       glVertex2s(i, values[i][1]);
   glEnd();

   glBegin(GL_LINE_STRIP);
   glColor3f(0.0, 0.0, 1.0);
   for ( i = 0; i < HISTOGRAM_SIZE; i++ )
       glVertex2s(i, values[i][2]);
   glEnd();
   glFlush();
}
Пример #2
0
void render(){
    //Clear color buffer
    glClear( GL_COLOR_BUFFER_BIT );
    //Render quad
    glBegin( GL_QUADS );
		glColor3f(1,0,0); glVertex2s( 100, 100 );
        glColor3f(0,1,0); glVertex2s( 100, 300 );
        glColor3f(0,1,1); glVertex2s( 300, 300 );
        glColor3f(1,0,1); glVertex2s( 300, 100 );
		/*
        glVertex2f( -0.5f, -0.5f );
        glVertex2f(  0.5f, -0.5f );
        glVertex2f(  0.5f,  0.5f );
        glVertex2f( -0.5f,  0.5f );
        */
        /*
        glVertex2f( 0.5f, 0.5f );
        glVertex2f( 0.5f, 0.8f );
        glVertex2f( 0.8f, 0.8f );
        glVertex2f( 0.8f, 0.5f );
        */
        
    glEnd();
    
    glutSwapBuffers();
    
}
Пример #3
0
void display() {
    glClear(GL_COLOR_BUFFER_BIT);
    glRasterPos2i(0, 0);
    glDrawPixels(checkImageWidth, checkImageHeight, GL_RGB, GL_UNSIGNED_BYTE, checkImage);

    int i;
    GLushort values[histogram_size][3];
    glGetHistogram(GL_HISTOGRAM, GL_TRUE, GL_RGB, GL_UNSIGNED_SHORT, values);

    glBegin(GL_LINE_STRIP);
        glColor3f(1.0, 0.0, 0.0);
        for (i = 0; i < histogram_size; i++)
            glVertex2s(i, values[i][0]);
    glEnd();

    glBegin(GL_LINE_STRIP);
        glColor3f(0.0, 1.0, 0.0);
        for (i = 0; i < histogram_size; i++)
            glVertex2s(i, values[i][1]);
    glEnd();

    glBegin(GL_LINE_STRIP);
        glColor3f(0.0, 0.0, 1.0);
        for (i = 0; i < histogram_size; i++)
            glVertex2s(i, values[i][2]);
    glEnd();

    glFlush();
}
Пример #4
0
void drawMarker(GLshort x, GLshort y)
{
    glBegin(GL_QUADS);
        glVertex2s(x-10, y-7);
        glVertex2s(x+10, y-7);
        glVertex2s(x+10, y+7);
        glVertex2s(x-10, y+7);
    glEnd();
}
Пример #5
0
void drawCheckBox(GLshort x, GLshort y, const char* text)
{
    glColor3f(0,0,0);
    glBegin(GL_LINE_LOOP);
        glVertex2s(x, y);
        glVertex2s(x+20, y);
        glVertex2s(x+20, y+20);
        glVertex2s(x, y+20);
    glEnd();
    displayText(text, x+25, y+5, 'm');
}
Пример #6
0
void Axes(void) {
    glColor3f (0.0, 0.0, 0.0);               // Set the color to BLACK
    glBegin(GL_LINES);                       // Plotting X-Axis
    glVertex2s(-1000 ,0);
    glVertex2s( 1000 ,0);
    glEnd();
    glBegin(GL_LINES);                       // Plotting Y-Axis
    glVertex2s(0 ,-1000);
    glVertex2s(0 , 1000);
    glEnd();
}
Пример #7
0
void drawCheck(GLshort x, GLshort y)
{
    glColor3f(0,0,0);
    glBegin(GL_LINES);
        glVertex2s(x, y);
        glVertex2s(x+20, y+20);
    glEnd();
    glBegin(GL_LINES);
        glVertex2s(x+20, y);
        glVertex2s(x, y+20);
    glEnd();
}
Пример #8
0
void BreshenHamLine(void){
	double dx=X2-X1;
	double  dy=X2-Y1;
	float x,y,p;
int i;
	x=X1,y=Y1;
	p=2*dy-dx;
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0,0.0,0.0);
	glBegin(GL_POINTS);
	glVertex2s(x,y);
	while(x<=X2){
		if(p<0){
			x=x+1;		
			y=y;
			p=p+2*dy;
			glVertex2s(roundValue(x),roundValue(y));
			printf("%lf %lf\n",x,y);
		}
		else{
			x=x+1;
			y=y+1;
			p=p+2*(dy-dx);
			glVertex2s(roundValue(x),roundValue(y));
			printf("%lf %lf\n",x,y);		
		}
	}
	

/* for(i=-100 ; i<=100 ; i++)
 {
 glVertex2s(i,0);
 glVertex2s(0,i);
 }
 for(i=-2; i<=2 ; i++)
 {
 glVertex2s(95+i,4+i);
 glVertex2s(95-i,4+i);
 } 
 for(i=0; i<=2 ; i++)
 {
 glVertex2s(4+i,95+i);
 glVertex2s(4-i,95+i);
 glVertex2s(4,95-i);
 }*/
	
	glEnd();
	glFlush();
}
Пример #9
0
void drawAnglePresets(GLshort percUnitW, GLshort percUnitH)
{
    int i,j;
    GLshort gapW = ((percUnitW*20)-30)/4;
    GLshort gapH = ((percUnitH*20)-30)/4;

    //set angle area box
    uiS.anglesBL[0] = percUnitW*55;
    uiS.anglesBL[1] = percUnitH*60;
    uiS.anglesTR[0] = percUnitW*75;
    uiS.anglesTR[1] = percUnitH*75;

    //draw angle area box
    glBegin(GL_LINE_LOOP);
        glVertex2sv(uiS.anglesBL);
        glVertex2s(uiS.anglesTR[0], uiS.anglesBL[1]);
        glVertex2sv(uiS.anglesTR);
        glVertex2s(uiS.anglesBL[0], uiS.anglesTR[1]);
    glEnd();

    for (i=0; i<3;i++){
        for (j=0;j<3;j++){
            //set angle preset location
            uiS.anglesPS[0][i*3+j] = percUnitW*60+i*gapW; // x
            uiS.anglesPS[1][i*3+j] = percUnitH*63+j*gapH; // y
            // draw radio button for angle preset
            drawHollowCircle(uiS.anglesPS[0][i*3+j], uiS.anglesPS[1][i*3+j], 10);
            if(!tmpState.angleRand){
                if(tmpState.angle == (i*3)+j+1){
                        drawFilledCircle(uiS.anglesPS[0][i*3+j], uiS.anglesPS[1][i*3+j], 8);
                }
            }
            else{
                //if random angle selected draw cross
                drawCheck(uiS.randAng[0], uiS.randAng[1]);
                //also need to draw a cross through the circles box to indicate out of use
                glBegin(GL_LINES);
                    glVertex2sv(uiS.anglesBL);
                    glVertex2sv(uiS.anglesTR);
                glEnd();
                glBegin(GL_LINES);
                    glVertex2s(uiS.anglesTR[0], uiS.anglesBL[1]);
                    glVertex2s(uiS.anglesBL[0], uiS.anglesTR[1]);
                glEnd();
            } // end if
        }// end for
    }// end for
}// end drawPresetAngles
Пример #10
0
//this acts as a replacement for GL_FillRect
void GL_FillRect(int x, int y, int w, int h, int color){
	//clear the color buffer
	//glClear( GL_COLOR_BUFFER_BIT );
	// quadrilateral
	glBegin(GL_QUADS);
	//process color
	glColor3ub(color/0x10000, (color/0x100)&0xff, color&0xff );
	//generate verticies
	glVertex2s(x,   y	);
	glVertex2s(x+h, y	);
	glVertex2s(x+h, y+h	);
	glVertex2s(x,   y+h	);
	//end the quad
	glEnd();
	RenderToDisplay();
}
Пример #11
0
	void SimplePlotter::plot( std::vector<float> &X, std::vector<float> &Y )
	{

		BasePlotter::drawBorders();

		properties.setAxesFromData( X, Y );

		// Draw the data lines
		glBegin( GL_LINES );
		bool lineStarted = true;
		for (int i=0; i<Y.size(); i++ )
		{
			int xPos = dataInXDimToGraphSpace(X[i]);
			int yPos = dataInYdimToGraphSpace(Y[i]);

			glVertex2s( xPos,yPos );

			if (lineStarted)
			{
				lineStarted = false;
			}
			else
			{
				i--;
				lineStarted = true;
			}
		}
		glEnd();


	}
Пример #12
0
bool _test_shader_(char *shader, const _test_type_list_& list) {
	GLuint program = ParseShader(shader);
	if (program) {

		glUseProgram(program);

		glBegin(GL_QUADS);

		glVertex2s(-1, -1);

		glVertex2s(1, -1);

		glVertex2s(1, 1);

		glVertex2s(-1, 1);

		glEnd();

		checkGLErrors();

		glFlush();

		for (unsigned x = 0; x < list.size(); ++x) {
			float test[4], e[4], a[4];
			glReadPixels(x, 0, 1, 1, GL_RGBA, GL_FLOAT, test);
			glReadPixels(x, 1, 1, 1, GL_RGBA, GL_FLOAT, e);
			glReadPixels(x, 2, 1, 1, GL_RGBA, GL_FLOAT, a);
			if (test[0] != 1.0f) {
				std::cout << "OpenGL GLSL subtest #" << x << " failed" << std::endl;
				if (test[0] == 2.0f) { // expected/actual available
					std::cout << "expected " << e[0] << " " << e[1] << " " << e[2] << " " << e[3]
					          << ", actual " << a[0] << " " << a[1] << " " << a[2] << " " << a[3]
					          << ", diff " << a[0]-e[0] << " " << a[1]-e[1] << " " << a[2]-e[2] << " " << a[3]-e[3]
					          << std::endl;
				}
				return false;
			}
		}
		return true;
	}
	return false;
}
Пример #13
0
static void wm_gesture_draw_rect(wmGesture *gt)
{
	rcti *rect = (rcti *)gt->customdata;
	
	glEnable(GL_BLEND);
	glColor4f(1.0, 1.0, 1.0, 0.05);
	glBegin(GL_QUADS);
	glVertex2s(rect->xmax, rect->ymin);
	glVertex2s(rect->xmax, rect->ymax);
	glVertex2s(rect->xmin, rect->ymax);
	glVertex2s(rect->xmin, rect->ymin);
	glEnd();
	glDisable(GL_BLEND);
	
	glEnable(GL_LINE_STIPPLE);
	glColor3ub(96, 96, 96);
	glLineStipple(1, 0xCCCC);
	sdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
	glColor3ub(255, 255, 255);
	glLineStipple(1, 0x3333);
	sdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
	glDisable(GL_LINE_STIPPLE);
}
Пример #14
0
void drawSlider(GLshort left[], GLshort right[])
{
    int i,j;
    GLshort between;
    bool done = false;

    //to find ideal between
    for(j=8; j<20; j++)
    {
        if((right[0]-left[0])%j == 0 && !done)
        {
            between = (right[0]-left[0])/j;
            done = true;
        }
    }

    //if can't find ideal between
    if(!done)
        between = 100;

    glColor3f(0,0,0);

    //draw main line
    glBegin(GL_LINES);
        glVertex2sv(left);
        glVertex2sv(right);
    glEnd();

    //draw interval markers
    for(i = 0; i <= (right[0] - left[0]); i = i + between)
    {
        glBegin(GL_LINES);
            glVertex2s(left[0]+i, left[1]+5);
            glVertex2s(left[0]+i, left[1]-5);
        glEnd();
    }
}
Пример #15
0
void drawFrame() {

	timeval t;
	gettimeofday(&t, 0);

	if (diff_in_micros(t, last_frame_time) < frame_time) return;

	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glClearColor(0.0f,0.0f,0.0f,0.0f);
	glClear(GL_COLOR_BUFFER_BIT);

	glLineWidth(5.0);
	glBegin(GL_LINE_STRIP);
		glVertex2s(1,1);
		glVertex2s(wX-1,1);
		glVertex2s(wX-1,wY-1);
		glVertex2s(1,wY-1);
		glVertex2s(1,1);
	glEnd();


	int j,k;
	float color = 0.0;
	glLineWidth(3.0);
	glBegin(GL_LINE_STRIP);
	for (std::list<pVect>::iterator iter = pList.begin(); 
			iter != pList.end(); 
			++iter, color += (1.0 / (float)nPoints)) {
		j = iter->x;
		k = iter->y;
		glColor3f(1.0 - color,0.0,color);
		glVertex2s(iter->x,iter->y);
	}
	glEnd();
	
	pList.pop_front();
	pVect foo(pList.back());
	if (bDown) {
		range++;
		foo.x += (rand() % range) * (foo.x - bVect.x < 0 ? 1 : -1);
		foo.y += (rand() % range) * (foo.y - bVect.y < 0 ? 1 : -1);
	} else {
		range = 16;
		foo.x += (rand() % 32) - 16;
		foo.y += (rand() % 32) - 16;
	}
	foo.pos();
	pList.push_back(foo);
	glutSwapBuffers();
	gettimeofday(&last_frame_time, 0);
}
Пример #16
0
/////////////////////////////////////////////////////////
// Render
//
void GEMglVertex2s :: render(GemState *state)
{
  glVertex2s (x, y);
}
Пример #17
0
void OpcodeState::paint( void )
{
  glPushMatrix();
  glLoadIdentity();
  glTranslatef( 0, 0, 0 );
  glBegin( GL_POLYGON );

  const double ff = 1.0/128; /* Mesa fudge factor */
  const double xoffset = 0.25; /* MPEG-2 style 4:2:0 subsampling */

  glMultiTexCoord2d( GL_TEXTURE0, ff, ff );
  glMultiTexCoord2d( GL_TEXTURE1, xoffset+ff, ff );
  glMultiTexCoord2d( GL_TEXTURE2, xoffset+ff, ff );
  glVertex2s( 0, 0 );

  glMultiTexCoord2d( GL_TEXTURE0, dispwidth+ff, ff );
  glMultiTexCoord2d( GL_TEXTURE1, dispwidth/2 + xoffset + ff, ff );
  glMultiTexCoord2d( GL_TEXTURE2, dispwidth/2 + xoffset + ff, ff );
  glVertex2s( width, 0 );

  glMultiTexCoord2d( GL_TEXTURE0, dispwidth+ff, dispheight+ff );
  glMultiTexCoord2d( GL_TEXTURE1, dispwidth/2 + xoffset + ff, dispheight/2 + ff);
  glMultiTexCoord2d( GL_TEXTURE2, dispwidth/2 + xoffset + ff, dispheight/2 + ff);
  glVertex2s( width, height);

  glMultiTexCoord2d( GL_TEXTURE0, ff, dispheight+ff );
  glMultiTexCoord2d( GL_TEXTURE1, xoffset+ff, dispheight/2 + ff );
  glMultiTexCoord2d( GL_TEXTURE2, xoffset+ff, dispheight/2 + ff );
  glVertex2s( 0, height);

  glEnd();

  glPopMatrix();

  glXSwapBuffers( display, window );

  OpenGLDisplay::GLcheck( "glXSwapBuffers" );

  glFinish();

  /* Check if we stuttered */  

  int64_t ust, mbc, sbc, us;
  struct timeval now;

  gettimeofday( &now, NULL );
  us = 1000000 * now.tv_sec + now.tv_usec;
  long us_diff = us - last_us;

  GetSync( display, window, &ust, &mbc, &sbc );

  bool msg = false;

  if ( (last_mbc != -1) && (mbc != last_mbc + 1) ) {
    long int diff = mbc - last_mbc;
    fprintf( stderr, "[Skipped %ld retraces.]", diff );
    msg = true;
  }

  if ( (last_us != -1) && ( (us_diff < 8000) || (us_diff > 24000) ) ) {
    fprintf( stderr, "%s[Time diff was %ld us.]", msg ? " " : "", (long)us_diff );
    msg = true;
  }

  if ( msg ) {
    fprintf( stderr, "\n" );
  }

  last_mbc = mbc;
  last_us = us;
}
Пример #18
0
// Display callback for GLUT
void Dimension_Display() {
	// Clear old things
	glClear(GL_COLOR_BUFFER_BIT);

	// Define Part, a logical unit of window measurement, useful for drawing
	auto Part=Dimension_Window_Size/100.0;

	// Draw a skeletal length of the old size
	glLineWidth(2);
	glColor3d(1, 1, 1);

	glScaled(Part, Part, 0);
	glBegin(GL_LINES); {
		glVertex2s(5, 4);
		glVertex2s(5, 2);
	} glEnd();

	glTranslated(5, 0, 0);
	for(auto n = 0; n < Old_Length; ++n) {
		glBegin(GL_LINE_STRIP); {
			glVertex2s( 0, 2);
			glVertex2s(10, 2);
			glVertex2s(10, 4);
		} glEnd();
		glTranslated(10, 0, 0);
	}
	glTranslated(-5 - 10*Old_Length, 0, 0);

	// Draw squares showing the current possible length
	glTranslated(5, 0, 0);
	for(auto n = 0; n < Current_Length; ++n) {
		glColor3d(.3, .3, .3);
		glBegin(GL_QUADS); {
			glVertex2s( 0,  5);
			glVertex2s(10,  5);
			glVertex2s(10, 15);
			glVertex2s( 0, 15);
		} glEnd();
		glColor3d(0, 0, 0);
		glBegin(GL_LINE_STRIP); {
			glVertex2s( 0,  5);
			glVertex2s(10,  5);
			glVertex2s(10, 15);
			glVertex2s( 0, 15);
			glVertex2s( 0,  5);
		} glEnd();
		glTranslated(10, 0, 0);
	}
	glTranslated(-5 - 10*Current_Length, 0, 0);
	glScaled(1/Part, 1/Part, 0);

	// Draw everything
	glutSwapBuffers();
}
Пример #19
0
void displayUISettings()
{
    // getting window dimensions
    GLshort w=glutGet(GLUT_WINDOW_WIDTH);
    uiS.height=glutGet(GLUT_WINDOW_HEIGHT);
    GLshort percUnitW = w/100;
    GLshort percUnitH = uiS.height/100;

    glDisable(GL_DEPTH_TEST);
    glClear(GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix(); //to prepare for return to 3D
    glLoadIdentity();
    gluOrtho2D(0,w,0,uiS.height);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    //UI background 20% of screen gap from edges
    glColor3f(1,1,1); //white
    glBegin(GL_QUADS);
        glVertex2s(percUnitW*20,percUnitH*20);
        glVertex2s(w-percUnitW*20,percUnitH*20);
        glVertex2s(w-percUnitW*20,uiS.height-percUnitH*20);
        glVertex2s(percUnitW*20,uiS.height-percUnitH*20);
    glEnd();

    glColor3f(0,0,1);
    displayText("SETTINGS:", percUnitW*22, percUnitH*78, 'l');

    //draw chosen colour if not random
    if(!tmpState.colourRand){
        uiS.chosenClr[0] = percUnitW*25;
        uiS.chosenClr[1] = percUnitH*55;
        glColor3fv(tmpState.colour);
        glBegin(GL_QUADS);
            glVertex2sv(uiS.chosenClr);
            glVertex2s(uiS.chosenClr[0]+20, uiS.chosenClr[1]);
            glVertex2s(uiS.chosenClr[0]+20, uiS.chosenClr[1]+20);
            glVertex2s(uiS.chosenClr[0], uiS.chosenClr[1]+20);
        glEnd();
        displayText("Chosen Colour", uiS.chosenClr[0]+25, uiS.chosenClr[1]+2, 'm');
    }

    //for colourpicker triangle
    drawColourPicker(percUnitW, percUnitH);
    //check box for selection of random colour
    uiS.randClr[0]=percUnitW*35;
    uiS.randClr[1]=percUnitH*55;
    drawCheckBox(uiS.randClr[0],uiS.randClr[1],"Random Colour");
    //if random colour selected draw cross
    if(tmpState.colourRand){
        drawCheck(uiS.randClr[0],uiS.randClr[1]);
    }

    //for selection of angle: draw a box then distribute evenly within 9 circles of radius 10, in 3 rows of 3, filled in for chosen angle
    drawAnglePresets(percUnitW, percUnitH);

    //check box for selection of random angle
    uiS.randAng[0] = percUnitW*60;
    uiS.randAng[1] = percUnitH*55;
    drawCheckBox(uiS.randAng[0], uiS.randAng[1] ,"Random Angle");

    //slider bar for selection of lift charge/intial velocity
    uiS.velocityL[0]= percUnitW*23;
    uiS.velocityL[1]= percUnitH*42;
    uiS.velocityR[0]= percUnitW*65;
    uiS.velocityR[1]= percUnitH*42;
    snprintf(uiS.velocityMnTxt, 6, "%4.1f", tmpState.velocityMin);
    snprintf(uiS.velocityMxTxt, 6, "%4.1f", tmpState.velocityMax);
    displayText("Lift Charge giving initial velocity in m/s:", uiS.velocityL[0]-20, uiS.velocityL[1]+15, 'm');
    drawSlider(uiS.velocityL, uiS.velocityR);
    displayText(uiS.velocityMnTxt, uiS.velocityL[0]-30, uiS.velocityL[1]-4, 'm');
    displayText(uiS.velocityMxTxt, uiS.velocityR[0]+5, uiS.velocityR[1]-4, 'm');

    //x coords of chosen velocity determined by (chosenValue - minValue)*((xRight - xLeft)/(maxValue-minValue)) + xLeft
    uiS.velocityChX = ((tmpState.velocityCh - tmpState.velocityMin)*(((float)uiS.velocityR[0]-(float)uiS.velocityL[0])/(tmpState.velocityMax-tmpState.velocityMin))+(float)uiS.velocityL[0]);
    drawMarker(uiS.velocityChX, uiS.velocityL[1]);
    snprintf(uiS.velocityChTxt, 6, "%3.1f", tmpState.velocityCh);
    displayText(uiS.velocityChTxt, uiS.velocityChX-10, uiS.velocityL[1]-17, 'm');

    //slider bar for selection of fuser timer
    uiS.fuseL[0]= percUnitW*23;
    uiS.fuseL[1]= percUnitH*32;
    uiS.fuseR[0]= percUnitW*65;
    uiS.fuseR[1]= percUnitH*32;
    snprintf(uiS.fuseMnTxt, 6, "%5.1f", tmpState.fuseMin);
    snprintf(uiS.fuseMxTxt, 6, "%5.1f", tmpState.fuseMax);
    displayText("Fuse timer from launch to explosion in milliseconds:", uiS.fuseL[0]-20, uiS.fuseL[1]+15, 'm');
    drawSlider(uiS.fuseL, uiS.fuseR);
    displayText(uiS.fuseMnTxt, uiS.fuseL[0]-40, uiS.fuseL[1]-4, 'm');
    displayText(uiS.fuseMxTxt, uiS.fuseR[0]+5, uiS.fuseR[1]-4, 'm');

    //x coords of chosen fuse determined by (chosenValue - minValue)*((xRight - xLeft)/(maxValue-minValue)) + xLeft
    uiS.fuseChX = ((tmpState.fuseCh - tmpState.fuseMin)*(((float)uiS.fuseR[0]-(float)uiS.fuseL[0])/(tmpState.fuseMax-tmpState.fuseMin))+(float)uiS.fuseL[0]);
    drawMarker(uiS.fuseChX, uiS.fuseL[1]);
    snprintf(uiS.fuseChTxt, 6, "%5.1f", tmpState.fuseCh);
    displayText(uiS.fuseChTxt, uiS.fuseChX-10, uiS.fuseL[1]-17, 'm');


    //save button
    uiS.saveBL[0] = percUnitW*70;
    uiS.saveBL[1] = percUnitH*31;
    uiS.saveTR[0] = percUnitW*79;
    uiS.saveTR[1] = percUnitH*39;
    glColor3f(0, 0.5, 0);
    glBegin(GL_QUADS);
        glVertex2sv(uiS.saveBL);
        glVertex2s(uiS.saveTR[0], uiS.saveBL[1]);
        glVertex2sv(uiS.saveTR);
        glVertex2s(uiS.saveBL[0], uiS.saveTR[1]);
    glEnd();
    displayText("Save", uiS.saveBL[0]+5, uiS.saveBL[1]+5,'l');
    //underline S
    glLineWidth(2);
    glBegin(GL_LINES);
        glVertex2s(uiS.saveBL[0]+6,uiS.saveBL[1]+3);
        glVertex2s(uiS.saveBL[0]+18,uiS.saveBL[1]+3);
    glEnd();
    glLineWidth(1);

    //cancel button
    uiS.cancelBL[0] = percUnitW*70;
    uiS.cancelBL[1] = percUnitH*22;
    uiS.cancelTR[0] = percUnitW*79;
    uiS.cancelTR[1] = percUnitH*30;
    glColor3f(0.6, 0, 0);
    glBegin(GL_QUADS);
        glVertex2sv(uiS.cancelBL);
        glVertex2s(uiS.cancelTR[0], uiS.cancelBL[1]);
        glVertex2sv(uiS.cancelTR);
        glVertex2s(uiS.cancelBL[0], uiS.cancelTR[1]);
    glEnd();
    displayText("Cancel", uiS.cancelBL[0]+5, uiS.cancelBL[1]+5,'l');
    //underline C
    glLineWidth(2);
    glBegin(GL_LINES);
        glVertex2s(uiS.cancelBL[0]+6,uiS.cancelBL[1]+3);
        glVertex2s(uiS.cancelBL[0]+18,uiS.cancelBL[1]+3);
    glEnd();
    glLineWidth(1);

    // returning to 3D
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    glEnable(GL_DEPTH_TEST);
}
Пример #20
0
int main() {
	// Create the main SFML window
	sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Canvas Example", sf::Style::Titlebar | sf::Style::Close );

	// We have to do this because we don't use SFML to draw.
	app_window.resetGLStates();

	// Create an SFGUI. This is required before doing anything with SFGUI.
	sfg::SFGUI sfgui;

	// Create our OpenGL canvas window
	sfg::Window::Ptr opengl_window;
	opengl_window = sfg::Window::Create();
	opengl_window->SetTitle( "OpenGL canvas" );
	opengl_window->SetPosition( sf::Vector2f( 100.f, 100.f ) );

	// Create our SFML canvas window
	sfg::Window::Ptr sfml_window;
	sfml_window = sfg::Window::Create();
	sfml_window->SetTitle( "SFML canvas" );
	sfml_window->SetPosition( sf::Vector2f( 400.f, 100.f ) );

	// Create our Canvas smart pointers.
	sfg::Canvas::Ptr opengl_canvas;
	sfg::Canvas::Ptr sfml_canvas;

	// Create the Canvases themselves.
	// Passing true in to Create() tells SFGUI
	// to create a depth buffer for the canvas.
	// This might be needed for your OpenGL rendering.
	// Specifying nothing defaults to no depth buffer.
	opengl_canvas = sfg::Canvas::Create( true );
	sfml_canvas = sfg::Canvas::Create();

	// Add the Canvases to the windows.
	opengl_window->Add( opengl_canvas );
	sfml_window->Add( sfml_canvas );

	// Create an sf::Sprite for demonstration purposes.
	sf::Texture texture;
	texture.loadFromFile( "data/sfgui.png" );
	sf::Sprite sprite;
	sprite.setTexture( texture );

	// Because Canvases provide a virtual surface to draw
	// on much like a ScrolledWindow, specifying their
	// minimum requisition is necessary.
	opengl_canvas->SetRequisition( sf::Vector2f( 200.f, 150.f ) );
	sfml_canvas->SetRequisition( sf::Vector2f( texture.getSize() ) );

	// Create a desktop to contain our Windows.
	sfg::Desktop desktop;
	desktop.Add( opengl_window );
	desktop.Add( sfml_window );

	sf::Clock clock;

	// Start the game loop
	while ( app_window.isOpen() ) {
		// Process events
		sf::Event event;

		while ( app_window.pollEvent( event ) ) {
			// Handle events
			desktop.HandleEvent( event );

			// Close window : exit
			if ( event.type == sf::Event::Closed ) {
				app_window.close();
			}
		}

		// Update the GUI, note that you shouldn't normally
		// pass 0 seconds to the update method.
		desktop.Update( 0.f );

		// Clear screen
		app_window.clear();

		// We bind the Canvases and draw whatever we want to them.
		// This must occur BEFORE the GUI is displayed.
		// You must not forget to set whatever context was active
		// before to active again after you unbind a Canvas.
		// Clear() takes an RGBA color and a bool which specifies
		// if you want to clear the depth buffer as well. In this
		// case, we do.

		// First the Canvas for OpenGL rendering.
		opengl_canvas->Bind();
		opengl_canvas->Clear( sf::Color( 0, 0, 0, 0 ), true );

		// Do some OpenGL drawing. If you don't intend
		// on drawing with OpenGL just ignore this section.
		glEnable( GL_DEPTH_TEST );
		glDepthMask( GL_TRUE );
		glDisable( GL_TEXTURE_2D );

		glMatrixMode( GL_MODELVIEW );
		glPushMatrix();
		glLoadIdentity();

		glTranslatef( 0.f, 0.f, -2.f );

		glRotatef( clock.getElapsedTime().asSeconds() * 30.f, 0.f, 0.f, 1.f );

		glDisable( GL_TEXTURE_2D );

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

		glViewport( 0, 0, static_cast<int>( opengl_canvas->GetAllocation().width ), static_cast<int>( opengl_canvas->GetAllocation().height ) );

		gluPerspective( 90.f, opengl_canvas->GetAllocation().width / opengl_canvas->GetAllocation().height, 1.f, 20.f );

		glBegin( GL_QUADS );
		glVertex2s( -1, 1 );
		glVertex2s( -1, -1 );
		glVertex2s( 1, -1 );
		glVertex2s( 1, 1 );
		glEnd();

		glPopMatrix();
		glMatrixMode( GL_MODELVIEW );
		glPopMatrix();

		glViewport( 0, 0, app_window.getSize().x, app_window.getSize().y );

		glEnable( GL_TEXTURE_2D );
		glDisable( GL_DEPTH_TEST );

		opengl_canvas->Display();
		opengl_canvas->Unbind();

		// Then the Canvas for SFML rendering.
		sfml_canvas->Bind();
		sfml_canvas->Clear( sf::Color( 0, 0, 0, 0 ) );

		// Draw the SFML Sprite.
		sfml_canvas->Draw( sprite );

		sfml_canvas->Display();
		sfml_canvas->Unbind();

		// This is important.
		app_window.setActive( true );

		// Draw the GUI
		sfgui.Display( app_window );

		// Update the window
		app_window.display();
	}

	return EXIT_SUCCESS;
}
Пример #21
0
void Canvas::DrawRenderTexture() {
	if( !m_render_texture ) {
		return;
	}

	if( !non_legacy_supported ) {
		// Matrix mode is currently GL_TEXTURE as set by Renderer.
		// We get ready for a surprise from SFML...
		CheckGLError( glPushMatrix() );
		sf::Texture::bind( &( m_render_texture->getTexture() ) );

		if( !m_display_list ) {
			m_display_list = glGenLists( 1 );

			if( !m_display_list ) {
#if defined( SFGUI_DEBUG )
				std::cerr << "SFGUI warning: Canvas failed to create OpenGL display list.\n";
#endif
			}

			CheckGLError( glNewList( m_display_list, GL_COMPILE ) );

			// Pop the texture matrix that SFML secretly loaded behind our backs...
			CheckGLError( glMatrixMode( GL_TEXTURE ) );
			CheckGLError( glPopMatrix() );

			CheckGLError( glColor3ub( 255, 255, 255 ) );

			// Oh the horror... not.
			CheckGLError( glMatrixMode( GL_MODELVIEW ) );
			CheckGLError( glPushMatrix() );
			CheckGLError( glLoadIdentity() );
			CheckGLError( glMatrixMode( GL_PROJECTION ) );
			CheckGLError( glPushMatrix() );
			CheckGLError( glLoadIdentity() );
			CheckGLError( glBegin( GL_QUADS ) );
			CheckGLError( glTexCoord2s( 0, 0 ) );
			CheckGLError( glVertex2s( -1, -1 ) );
			CheckGLError( glTexCoord2s( 1, 0 ) );
			CheckGLError( glVertex2s( 1, -1 ) );
			CheckGLError( glTexCoord2s( 1, 1 ) );
			CheckGLError( glVertex2s( 1, 1 ) );
			CheckGLError( glTexCoord2s( 0, 1 ) );
			CheckGLError( glVertex2s( -1, 1 ) );
			CheckGLError( glEnd() );
			CheckGLError( glPopMatrix() );
			CheckGLError( glMatrixMode( GL_MODELVIEW ) );
			CheckGLError( glPopMatrix() );
			CheckGLError( glMatrixMode( GL_TEXTURE ) );

			CheckGLError( glEndList() );
		}

		CheckGLError( glCallList( m_display_list ) );
	}
	else {
		// Non-Legacy
		if( !m_shader ) {
			SetupShader();
		}

		if( !non_legacy_supported ) {
			// Fall back to legacy starting in this frame.
			DrawRenderTexture();
			return;
		}

		if( !m_vbo ) {
			SetupVBO();
		}

		auto is_vertex_array = CheckGLError( GLEXT_glIsVertexArray( m_vao ) );

		if( !is_vertex_array ) {
			SetupVAO();
		}

		struct Texture : sf::GlResource {
			sf::Vector2u unused1;
			sf::Vector2u unused2;
			unsigned int unused3;
			bool unused4;
			bool unused5;
			mutable bool pixels_flipped;
			sf::Uint64 unused6;
		};

		// Just so that SFML doesn't mess with the texture matrix.
		const_cast<Texture*>( reinterpret_cast<const Texture*>( &( m_render_texture->getTexture() ) ) )->pixels_flipped = false;

		sf::Shader::bind( m_shader.get() );

		CheckGLError( GLEXT_glBindVertexArray( m_vao ) );

		CheckGLError( glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 ) );

		CheckGLError( GLEXT_glBindVertexArray( 0 ) );

		sf::Shader::bind( nullptr );
	}
}
Пример #22
0
inline void glVertex( const GLshort & x, const GLshort & y )	{ glVertex2s( x, y ); }
Пример #23
0
M(void, glVertex2s, jshort x, jshort y) {
	glVertex2s(x, y);
}