Thread: How to creat an array function?

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    26

    How to creat an array function?

    Hey guys,

    Can someone please tell me how can i creat an array function? I want to draw multiple 3-D triangles in open GL. I've drew one and want drew more than one using arrays. I would apperciate the help. Thanks in advance. Below is the code for reference:

    Code:
    int DrawGLScene(GLvoid)	{
    	
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	//   Clear Screen And Depth Buffer
    
    	glLoadIdentity();  			              // Reset The Current Modelview Matrix
    	
    	glTranslatef(-1.5f, 0.0f, -6.0f);			// Move Triangle Left 1.5 Units And Into The Screen 6.0
    	glRotatef(rtri, 0.0f, 1.0f, 0.0f);			// Rotate The Triangle On The Y axis 
    	draw3DTri();                                                           // calling draw3DTri() function which draws 3-D Triangle
    
    
    int draw3DTri() {
    	 
    	glBegin(GL_TRIANGLES);		// Drawing Using Triangles
    	
    	   // Front side of Triangle								
    	   glColor3f(1.0f,0.0f,0.0f);			// Red	   
    		glVertex3f( 0.0f, 1.0f, 0.0f);			// Top 		
    		glColor3f(0.0f,1.0f,0.0f);			// Green		
    		glVertex3f(-1.0f, -1.0f, 1.0f);			// Left 		
    		glColor3f(0.0f,0.0f,1.0f);			// Blue		
    		glVertex3f( 1.0f,-1.0f, 1.0f);			// Right 
    		
    		
    		// Right side of Triangle
    		glColor3f(1.0f,0.0f,0.0f);			// Red
    		glVertex3f( 0.0f, 1.0f, 0.0f);			// Top 
    		glColor3f(0.0f,0.0f,1.0f);			// Blue
    		glVertex3f( 1.0f,-1.0f, 1.0f);			// Left 
    		glColor3f(0.0f,1.0f,0.0f);			// Green
    		glVertex3f(1.0f, -1.0f, -1.0f);			// Right 
    				
    		// Back side of Triangle
    		glColor3f(1.0f,0.0f,0.0f);			// Red
    		glVertex3f( 0.0f, 1.0f, 0.0f);			// Top 
    		glColor3f(0.0f,1.0f,0.0f);			// Green
    		glVertex3f(1.0f, -1.0f, -1.0f);			// Left 
    		glColor3f(0.0f,0.0f,1.0f);			// Blue
    		glVertex3f( -1.0f,-1.0f, -1.0f);			// Right
    		
    		// Left side of Triangle
    		glColor3f(1.0f,0.0f,0.0f);			// Red
    		glVertex3f( 0.0f, 1.0f, 0.0f);			// Top 
    		glColor3f(0.0f,0.0f,1.0f);			// Blue
    		glVertex3f( -1.0f, -1.0f, -1.0f);			// Left 
    		glColor3f(0.0f,1.0f,0.0f);			// Green
    		glVertex3f(-1.0f, -1.0f, 1.0f);			// Right 
    		
    		
    	glEnd();											// Finished Drawing The Triangle 
    	 
    	return 0; 
    }

  2. #2
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    You mean an array of functions? I tried it before and my compiler didn't allow it.
    Code:
    void function(void)
     {
      function();
     }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Array Allocation function
    By P4R4N01D in forum C++ Programming
    Replies: 6
    Last Post: 05-15-2009, 02:04 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Passing my array to function
    By pooty tang in forum C Programming
    Replies: 8
    Last Post: 09-15-2004, 12:19 PM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM