PDA

View Full Version : i m not gettting the line and the arc. plz check it out



sumanmali
04-26-2016, 04:38 PM
#include<stdio.h>
#include<math.h>
#include<GL/glut.h>

GLfloat x,y;

void line()
{
glColor3f(1.0,1.0,1.0);
glBegin(GL_LINES);
glVertex3f(5.0,4.0,1.0);
glVertex3f(3.0,5.0,7.0);
glEnd();
glFlush();
}

void hole()
{
glClearColor(0.0,0.0,0.0,1.0);
glColor3f(1.0,1.0,1.0);
glBegin(GL_TRIANGLE_FAN);
for(int i=-150;i<150;i++)
{
x=cos(1*3.1415926*i/1000.0);
y=sin(1*3.1415926*i/1000.0);
glVertex3f(x,y,0.0);
}
glEnd();
glFlush();
}


void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
hole();
line();
glFlush();
glutSwapBuffers();
}


void myinit()
{
glClearColor(1.0,0.0,0.0,1.0);
glColor3f(1.0,1.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,499.0,0.0,499.0,-10.0,10.0);
}


void myReshape(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
glOrtho(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLfloat)w,-10.0,10.0);
else
glOrtho(-2.0*(GLfloat)w/(GLfloat)h,2.0*(GLfloat)h/(GLfloat)w,-2.0,2.0,-10.0,10.0);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("ATRY");
glutDisplayFunc(display);
glutReshapeFunc(myReshape);
myinit();
glutMainLoop();
}

sumanmali
04-26-2016, 04:52 PM
:confused:

mhagain
04-27-2016, 04:55 AM
You're not going to get any help for a "plz fix my code for me" post. Can you at least demonstrate that you've tried yourself, rather than just give a code dump and expect other people to use psychic powers to figure it out for you? And it's "please", not "plz"; that's really annoying.