Need some help drawing a cylinder in openGL

This is a discussion on Need some help drawing a cylinder in openGL within the Game Programming forums, part of the General Programming Boards category; Been a long time since i last posted here. How is everyone hehe. Lately ive been reading on some openGL ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    494

    Need some help drawing a cylinder in openGL

    Been a long time since i last posted here. How is everyone hehe.

    Lately ive been reading on some openGL stuff and need some help with a simple program. My problem is that i cant get the cylinder to be displayed, i only get 3 warnings but then there is nothing on the screen.

    Code:
    #include <stdio.h>
    #include <GL/glut.h>
    
    
    int wf = 1; /*wireframe*/
    void display()
    {
    	/*clear window*/
    	glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    	glLineWidth(2.0);
    	glColor3f(0.5, 1.0, 0.1);
    
    }
    				 
    void Idelfunc()
    {
    	glutPostRedisplay();
    }
    
    void  init()
    { 
    	/*set clear color to black*/
    	glClearColor (0.0, 0.0, 0.0, 0.0);
    	/*set fill color to yellow*/
    	glColor3f(0.0, 0.6, 0.9);
    	{
    		glEnable (GL_DEPTH_TEST);
    		glCullFace(GL_BACK);
    		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    	}
    
    	/*Cylinder*/
    	{
    		void Cylinder (double height, double radius, int slices, int stacks);
    
    			GLUquadricObj* cyl;
    			cyl = gluNewQuadric();
    			gluQuadricDrawStyle(cyl, GLU_LINE);
    			gluCylinder(cyl, 3, 3, 5, 12, 12);
    	}	
    	
    }
    
    void keys (unsigned char key1, int x, int y)
    {
    	switch (key1)
    	{
    		//view in wireframe
    	case 'v':
    		wf = 1-wf;
    			if (wf) 
    				{
    					glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    				}
    			else
    				{
    					glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    				}
    				glutPostRedisplay();
    	break;
    	case 'q':
    	if (key1 =='q' || key1 =='Q' ||key1 =='\27') exit(0);
    
    	}
    }
    
    int main( int argc, char** argv)
    {
    	/*initialize mode and open a window in upper-left corner of screen*/
    	
    	glutInit(&argc,argv);
    	glutInitDisplayMode(GLUT_SINGLE |GLUT_RGB);
    	glutInitWindowSize(500, 500);
    	glutInitWindowPosition(0,0);
    	glutCreateWindow("Cylinder"); 
    	glutDisplayFunc(display);
    
    	init();
    //	glutReshapeFunc(myreshape);
    	glutIdleFunc(Idelfunc);
    	glutKeyboardFunc(keys);
    	glutMainLoop();
    }
    When no one helps you out. Call google();

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    It does not look like you are actually calling your Cylinder() function during the draw function...

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    The Cylinder is inside init() and im calling init() on main?
    When no one helps you out. Call google();

  4. #4
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200
    I think you should draw the cylinder right into main.
    Code:
    void Cylinder (double height, double radius, int slices, int stacks);
    As i know, you will use this function to draw a cylinder, like this in main
    Code:
    Cylinder(100, 10, 2, 2);
    When you put init() into main, it did not run the void Cylinder because there is no value pass into it.

    Wait.. Why do you need a void Cylinder when you already have a draw cylinder function?
    Last edited by hdragon; 10-24-2005 at 10:01 PM.

  5. #5
    ---
    Join Date
    May 2004
    Posts
    1,379
    You need to draw the cylinder in the display function.
    Your code doesn't make a whole lot of sense really. Why is there a function prototype:
    Code:
    void Cylinder (double height, double radius, int slices, int stacks);
    but no definition. And why did you put the prototype in the init function? I'm sure it probably compiles fine but it just doesn't make any sense.

    Let's say the init() did actually draw you a cylinder. You wouldn't be able to see it because the display function is looped and
    Code:
    glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    Clear's everything that was drawn ready for the next frame so you won't be able to see anything that was drawin in init().
    Last edited by sand_man; 10-25-2005 at 03:23 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you make games without drawing in OpenGL?
    By Jake.c in forum Game Programming
    Replies: 9
    Last Post: 02-11-2009, 10:00 AM
  2. drawing my ui (openGL)
    By hannibar in forum Game Programming
    Replies: 1
    Last Post: 04-12-2006, 08:24 AM
  3. OpenGL Linux Line Drawing Problem
    By swanley007 in forum C++ Programming
    Replies: 2
    Last Post: 04-03-2006, 10:31 AM
  4. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21