21-03-2015, 05:24 PM
Yes...i need code for go back n arq in opengl..
source code of go back n arq on opengl
|
001
#include<stdio.h>
002
#include<GL/glut.h>
003
void send();
004
void ack();
005
int i,n,m;
006
void drawrect()
007
{
008
int x1=100,x2=200,x3=300,x4=400,y1=200,y2=300,y3=400,y4=500;
009
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
010
glColor3f(1.0,0.0,0.0);
011
for(i=0;i<(3*100);i+=100)
012
{
013
glBegin(GL_POLYGON);
014
glVertex2d(x1,y1+i);
015
glVertex2d(x2,y2+i);
016
glVertex2d(x2,y3+i);
017
glVertex2d(x1,y4+i);
018
glEnd();
019
}
020
for(i=0;i<(3*100);i+=100)
021
{
022
glBegin(GL_POLYGON);
023
glVertex2d(x3,y1+i);
024
glVertex2d(x4,y2+i);
025
glVertex2d(x4,y3+i);
026
glVertex2d(x3,y4+i);
027
glEnd();
028
}
029
glFlush();
030
glutSwapBuffers();
031
}
032
static void (*draw)(void) = send;
033
void init()
034
{
035
glClearColor(1.0,1.0,1.0,1.0);
036
glMatrixMode(GL_PROJECTION);
037
glLoadIdentity();
038
gluOrtho2D(0.0,599.0,0.0,599.0);
039
}
040
void display()
041
{
042
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
043
glColor3f(1.0,0.0,0.0);
044
glBegin(GL_LINES);
045
glVertex2d(150,100);
046
glVertex2d(150,400);
047
glEnd();
048
glBegin(GL_LINES);
049
glVertex2d(400,100);
050
glVertex2d(400,400);
051
glEnd();
052
glRasterPos(75,450);
053
glutBitmapCharacter(GLUT_BITMAP_8_BY_13,'S');
054
send();
055
ack();
056
if(m=n)
057
printf("data delivered succesfully\n");
058
glFlush();
059
glutSwapBuffers();
060
}
061
void send()
062
{
063
int x1=150,y1=375,x2=400,y2=325;
064
glColor3f(0.0,0.0,0.0);
065
for(i=0;i<(n*20);i+=20)
066
{
067
glBegin(GL_LINES);
068
glVertex2i(x1,y1-i);
069
glVertex2i(x2,y2-i);
070
glEnd();
071
072
073
}
074
printf("DATA SENT\n");
075
}
076
void ack()
077
{
078
int x3=150,y3=275,x4=400,y4=325;
079
glColor3f(0.0,1.0,0.0);
080
for(i=0;i<(m * 20);i+=20)
081
{
082
glBegin(GL_LINES);
083
glVertex2i(x3,y3-i);
084
glVertex2i(x4,y4-i);
085
glEnd();
086
087
088
}
089
printf("ACKNOWLEDGEMENT RECIEVED\n");
090
}
091
void main(int argc,char **argv)
092
{
093
printf("enter the no of data to be sent\n");
094
scanf_s("%d",&n);
095
printf("enter the no of acknowledgements to be recieved\n");
096
scanf_s("%d",&m);
097
glutInit(&argc,argv);
098
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
099
glutCreateWindow("GO BACK N ARQ");
100
glutInitWindowSize(600,600);
101
glutDisplayFunc(display);
102
103
glutCreateWindow("ARQ DIAGRAM");
104
glutInitWindowSize(500,500);
105
glutDisplayFunc(drawrect);
106
107
init();
108
glutMainLoop();
109
}
« Next Oldest | Next Newest »
|
Tagged Pages: selective repeat arq open gl source code, |