1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#include <Windows.h>
#include <GL/glut.h>
#include "screen_interface.h"
struct vertex
{
GLint wx, wy;
vertex( void ) : wx( 0 ), wy( 0 ) { }
vertex( GLint x, GLint y ) : wx( x ), wy( y ) { }
};
MSG msg;
unsigned char key_pressed( void );
int WINAPI WinMain( HINSTANCE hinst, HINSTANCE pinst, LPSTR cmdl, int cmds )
{
screen_interface.open_window( hinst, 640, 480 );
vertex a( 80, 80 );
vertex b( 560, 400 );
vertex c( 160, 150 );
vertex d( 480, 330 );
glClearColor( 0.25f, 0.2f, 1, 0 );
glClear( GL_COLOR_BUFFER_BIT );
while( 1 )
{
if( key_pressed() ) break;
vertex pos;
pos.wx = a.wx + (rand() % (b.wx - a.wx + 1));
pos.wy = a.wy + (rand() % (b.wy - a.wy + 1));
if( pos.wx >= c.wx && pos.wx <= d.wx && pos.wy >= c.wy && pos.wy <= d.wy )
continue;
glBegin( GL_POINTS );
GLubyte c = rand() % 256;
glColor3ub( c, c, c );
glVertex2i( pos.wx, pos.wy );
glEnd();
}
return msg.wParam;
}
unsigned char key_pressed( void )
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
if( msg.message == WM_QUIT || msg.message == WM_KEYDOWN ) return 1;
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return 0;
}
|