-
Leka
-
-
Не в сети
-
Живу я здесь
-
-
Сообщений: 635
-
Спасибо получено: 54
-
-
|
Вот написал, к примеру, простенькую программу на Си с использованием openGL (для тренировки, раньше графику только на Паскале писал) - и смотрю, легко или сложно будет сделать то-же самое на чистом HDL(с целью синтеза, и без каких-либо софт процессоров), и на дешевых ПЛИС. #include <stdlib.h>
#include <GL/glut.h>
#define N 8
int Width=1024, Height=768;
int x1[N]={100,120,140,160,180,200,220,240};
int x2[N]={200,220,240,260,280,300,320,340};
int y1[N]={100,120,140,160,180,200,220,240};
int y2[N]={200,220,240,260,280,300,320,340};
int stX = 0, stY = 0;
int xx = 0, yy = 0;
int xx0 = 0, yy0 = 0;
void Display( void ) {
int i;
glClearColor( 0, 0, 0, 1 );
glClear( GL_COLOR_BUFFER_BIT );
for(i=N-1;i>=0;i--){
if(i==0)
glColor3f( 0, 0.75, 0 );
else
glColor3f( 0, 0.5, 0 );
glBegin( GL_QUADS );
glVertex2i( x1[i], y1[i] );
glVertex2i( x2[i], y1[i] );
glVertex2i( x2[i], y2[i] );
glVertex2i( x1[i], y2[i] );
glEnd();
glColor3f( 1, 0, 0 );
glBegin( GL_LINE_LOOP );
glVertex2i( x1[i], y1[i] );
glVertex2i( x2[i], y1[i] );
glVertex2i( x2[i], y2[i] );
glVertex2i( x1[i], y2[i] );
glEnd();
}
glColor3f( 1, 1, 1 );
glBegin( GL_POINTS );
glVertex2i( xx, yy );
glEnd( );
glFlush( );
}
void Reshape( int w, int h ) {
Width = w;
Height = h;
glViewport( 0, 0, w, h );
glMatrixMode( GL_PROJECTION );
glLoadIdentity( );
glOrtho( 0, w, 0, h, -1, 1 );
glPointSize( 10 );
glLineWidth( 1 );
}
void MouseMove( int x, int y ) {
xx = x;
yy = Height - y;
xx0 = xx;
yy0 = yy;
glutPostRedisplay( );
}
void MouseActiveMove( int x, int y ) {
int dx, dy;
xx = x;
yy = Height - y;
if( stX == 1 ) x1[0] = xx;
if( stX == 2 ) x2[0] = xx;
if( stY == 1 ) y1[0] = yy;
if( stY == 2 ) y2[0] = yy;
if( ( stX == 3 ) & ( stY == 3 ) ) {
dx = xx - xx0;
dy = yy - yy0;
xx0 = xx;
yy0 = yy;
x1[0] = x1[0] + dx;
x2[0] = x2[0] + dx;
y1[0] = y1[0] + dy;
y2[0] = y2[0] + dy;
}
glutPostRedisplay( );
}
void Mouse( int button, int state, int x, int y ) {
int i,n,t,xx1,xx2,yy1,yy2;
int yy;
yy = Height - y;
n=-1;
for(i=N-1;i>0;i--)
if( ( x1[i] < x ) & ( x < x2[i] ) & ( y1[i] < yy ) & ( yy < y2[i] ) )
n=i;
if( ( (x1[0]-5) <= x ) & ( x <= (x2[0]+5) ) & ( (y1[0]-5) <= yy ) & ( yy <= (y2[0]+5) ) )
n=0;
if( n>0 ) {
xx1=x1[n];
xx2=x2[n];
yy1=y1[n];
yy2=y2[n];
for(i=n;i>0;i--) {
x1[i]=x1[i-1];
x2[i]=x2[i-1];
y1[i]=y1[i-1];
y2[i]=y2[i-1];
}
x1[0]=xx1;
x2[0]=xx2;
y1[0]=yy1;
y2[0]=yy2;
}
if( state == GLUT_DOWN ) {
if( button == GLUT_LEFT_BUTTON ) {
if( ( x1[0] < x ) & ( x < x2[0] ) & ( y1[0] < yy ) & ( yy < y2[0] ) ) {
stX = 3;
stY = 3;
}
if( ( (x1[0] - 5) <= x ) & ( x <= (x1[0] + 5) ) & ( y1[0] <= yy ) & ( yy <= y2[0] ) )
stX = 1;
if( ( (x2[0] - 5) <= x ) & ( x <= (x2 [0]+ 5) ) & ( y1[0] <= yy ) & ( yy <= y2[0] ) )
stX = 2;
if( ( (y1[0] - 5) <= yy ) & ( yy <= (y1[0] + 5) ) & ( x1[0] <= x ) & ( x <= x2[0] ) )
stY = 1;
if( ( (y2[0] - 5) <= yy ) & ( yy <= (y2[0] + 5) ) & ( x1[0] <= x ) & ( x <= x2[0] ) )
stY = 2;
}
} else {
stX = 0;
stY = 0;
if( x1[0] > x2[0] ) {
t=x1[0];
x1[0]=x2[0];
x2[0]=t;
}
if( y1[0] > y2[0] ) {
t=y1[0];
y1[0]=y2[0];
y2[0]=t;
}
}
glutPostRedisplay( );
}
void Keyboard( unsigned char key, int x, int y ) {
const char ESCAPE = '\033';
if( key == ESCAPE )
exit( 0 ) ;
}
void main ( int argc, char** argv ) {
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB );
glutInitWindowSize( Width , Height );
glutInitWindowPosition( 128, 128 );
glutCreateWindow( "Test" );
glutDisplayFunc( Display );
glutReshapeFunc( Reshape );
glutKeyboardFunc( Keyboard );
glutMouseFunc( Mouse );
glutMotionFunc( MouseActiveMove );
glutPassiveMotionFunc( MouseMove );
glutMainLoop( );
}
|