#include <windows.h> /* windows's header file */#include <gl/gl.h Header file for > /* opengl32 library */#include <gl/glu.h> Header files for /* glu32 library *//* #include <gl/glaux.h> Header file for // glaux library */#include <gl/glut.h> /* glut library header file * /#include <time.h> #include <iostream>using namespace std;intaa[20][20]; int xx = 0; int yy = 0;intscreenwidth= 640;intscreenheight= 480; intcc= 0;/* global variable */int winwidth ( 500 ), winheight ( 500 ); #define max_char 128void initialization () {Glclearcolor ( 1.0f, 1.0f, 1.0f, 1.0f ); /* set the background color to white */}void onreshape ( int w, int h ) {winwidth= w;winheight= h;glViewport ( 0, 0, w, h ); /* Setting the viewport size */glmatrixmode ( GL_PROJECTION ); /* projection mode */glloadidentity (); /* load the unit matrix to initialize the current matrix */ Gluortho2d ( 0, w, 0, h ); /* Sets the current drawing area to two-dimensional orthographic projection */glmatrixmode ( GL_MODELVIEW ); /* Model view mode */ Glloadidentity (); /* Initialize current matrix */}void drawstring ( const char* str ) /* Screen display Fonts */{static intisFirstCall = 1;static GLuintlists;if ( isFirstCall ) {isfirstcall = 0;/* application Max_char consecutive display list number */lists = Glgenlists ( MAX_CHAR );/* The painting of each characterCommands are loaded into the corresponding display list */wglusefontbitmaps (&NBSP;WGLGETCURRENTDC (), 0, max_char, lists );} /* calls each character corresponding to the display list, drawing each character */for (; *str != '; ++str ) {glcalllist ( lists + *str );}} Void ondisplay () {glclear ( GL_COLOR_BUFFER_BIT ); glcolor3f ( 0.0f, 0.0f, 0.0f ); /* Set font color */glrasterpos2i ( 0, winheight - 15 ); /* start position */drawstring ( " hello,opengl. " ); /* output String */glutswapbuffers (); /* before and after buffer */}void myinit () {Glclearcolor ( 1.0, 1.0, 1.0, 0.0 );/* set the background color to bright white */glcolor3f (&NBSP;0.0F,&NBSP;0.0F,&NBSP;0.0F&NBSP;);/* set the drawing color to Black */glpointsize ( 4.0 );/* the size of the set point to 4*4 pixels */glmatrixmode ( gl_ projection );/* set the appropriate matrix */glloadidentity (); gluortho2d ( 0.0, screenwidth, 0.0, screenHeight );} Void mymouse2 ( int button, int state, int x, int y ) {if ( state == GLUT_DOWN ) {if ( button == GLUT_RIGHT_BUTTON ) { Glclearcolor ( 1.0f, 0.0f, 0.0f, 0.0f ); Glclear ( GL_COLOR_BUFFER_BIT ); Glflush ();}} return;} Void drawdot ( int x, int y ) {xx = (x - 30) / 20; yy = y / 20;glbegin ( GL_POINTS ); Glvertex2i ( x, y );/* Draw some points */if ( 30 < x && x < 430 && 0 < y && y < 400 ) cc++;/* aa[yy][xx] == 0; thought 1 */cout << cc << endl;if ( cc >= 4 ) {glvertex2i ( 450, 450 );/* ideas 3 */mymouse2 ( glut_right_ button, glut_down, 300, 400 );} Glend ();} Void mymouse ( int button, int state, int x, int y ) {if ( state == GLUT_DOWN ) {if ( button == GLUT_LEFT_BUTTON ) {Drawdot ( x, screenheight - y ); Glflush ();} else if ( button == GLUT_RIGHT_BUTTON ) {Glclearcolor ( 1.0f, 0.0f, 0.0f, 0.0f ); Glclear ( GL_COLOR_BUFFER_BIT ); Glflush ();}} return;} Void mydisplay () {glclear ( GL_COLOR_BUFFER_BIT );/* clear screen */glbegin ( GL_POINTS );/* draw some points */for ( int i = 0; i < 20; i++ ) {for ( int j = 0; j < 20; j++ ) {if ( aa[i][j] == 1 ) glvertex2i ( i * 20 + 33, j * 20 + 5 );}} Glend (); Glfloat cursizeline = 2;gllinewidth ( curSizeLine ); Glbegin ( GL_LINES ); for ( int i = 0; i <= 400; ) {glvertex3f ( 30, 0.0 + i, 0.0f ); glvertex3f ( 430, 0.0 + i, 0.0f ); glvertex3f ( 30.0 + i, 0, 0.0f ); glvertex3f ( 30.0 + i, 400, 0.0f ); i += 20;} Glend (); Glflush ();/* send all output to display device */}void funrand () {int s = 4; int x = 0; int y = 0;srand ( time ( 0 ) );while ( s-- ) {X= rand () % 20; y = rand () % 20;aa[x][y]= 1;}} Int check () {For ( int i = 0; i < 20; i++ ) {for ( int j = 0; j < 20; j++ ) {if ( aa[i][j] == 1 ) return (1);}} return (0);} Void main ( int argc, char **argv ) {Funrand (); Glutinit ( &argc, argv ); /* init kit */glutinitdisplaymode ( glut_single | GLUT_RGB ); /* Set display mode */glutinitwindowsize ( 640, 480 ); /* Set Window Size */glutinitwindowposition ( 100, 150 ); /* set the position of the window on the screen */glutcreatewindow ( "Everyone to find fault, find some" ); /* Open Screen window //Registration callback function */initialization (); Glutdisplayfunc ( myDisplay ); Glutmousefunc ( myMouse ); Myinit (); Glutreshapefunc ( OnReshape ); /* Redraw functions Print prompt Information */glutmainloop (); /* Enter Loop */}/****************** implement mouse monitor * Run effect for the panel dot **bug1 dot out of bounds * Some points can return 1 some points do not * * * fuzzy judgment ****************/
OpenGL first Mini-game