why this code is not working
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement