Jump to content
  • Advertisement
Sign in to follow this  
abt

OpenGL why this code is not working

This topic is 3805 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have written a opengl code using glutKeyboardFunc function so that i can control the shape of the cylinder i have created here from keyboard. but this code is not working . here is the code #include<stdio.h> #include<GL\glut.h> #include<windows.h> void init() { glClearColor(.1,.10,.10,0); } void reshape(int w, int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(50,1,0,15); glMatrixMode(GL_MODELVIEW); } void drawaxis() { glBegin(GL_LINES); glColor3f(0.0, 1.0, 0.0); glVertex2f(2.0, 0.0); glColor3f(1.0, 0.0, 0.0); glVertex2f(-2.0, 0.0); glColor3f(0.0, 0.0, 1.0); glVertex2f(0.0, 2.0); glColor3f(1.0, 1.0, 0.0); glVertex2f(0.0, -2.0); glEnd(); } void Cylinder (double height, double radius, int slices, int stacks) { GLUquadricObj* cyl; cyl = gluNewQuadric(); gluQuadricDrawstyle(cyl, GLU_LINE); gluCylinder(cyl, 1, 1, 3, 6, 6); } void square() { glBegin(GL_POLYGON); glVertex3d(-0.25,0.25,0); glVertex3d(0.25,0.25,0); glVertex3d(0.25,-0.25,0); glVertex3d(-0.25,-0.25,0); glEnd(); } //glTranslated(0,0,-5); //glRotated(10,0,1,0); void render() { glClear(GL_COLOR_BUFFER_BIT); glColor3d(1,0,1); glLoadIdentity(); gluLookAt(0,0,5,0,0,0,0,1,0); glTranslated(0,0,-2); glRotated(30,0,1,0); //glutWireCube(1); drawaxis(); Cylinder(100, 10, 2, 2); glFlush(); } void keyboard(unsigned char key, int x, int y) { switch (key) { case 'u': case 'U': glRotatef(3.0, 1.0, 0.0, 0.0); // rotate up break; case 'd': case 'D': glRotatef(-3.0, 1.0, 0.0, 0.0); // rotate down break; case 'l': case 'L': glRotatef(3.0, 0.0, 1.0, 0.0); // rotate left break; case 'r': case 'R': glRotatef(-3.0, 0.0, 1.0, 0.0); // rotate right } glutPostRedisplay(); } int main(int argc, char* argv[]) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(300, 300); glutInitWindowPosition(100,100); glutCreateWindow("hello window"); init(); glutDisplayFunc(render); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; } can someone tell me what is wrong with this code.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by abt
but this code is not working .


How so? What behavior do you expect, and what behavior are you getting? What steps have you taken to debug the problem yourself?

We can help you a lot more easily if you provide us with a more detailed description of the problem.

Share this post


Link to post
Share on other sites

This topic is 3805 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!