Total members 10249 | Gratitudes |It is currently Thu May 17, 2012 9:39 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: Drawing a triangle with colors
PostPosted: Mon Mar 14, 2011 1:06 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2272
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

Code:
#include <cstdlib>
#include <GL/glut.h>
#include <GL/glut.h>
 


void displayFunc
(void)
{
    // Clear the current buffer before drawing .
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();
    // Draw polygon 
    glBegin(GL_POLYGON);
    {
        // change color 
        glColor3f(0.0,1.0,0.0);
        // set point
        glVertex3f(-0.4,-0.5,-3.0);
        // change color 
        glColor3f(1.0,0.0,0.0);
        // set point
        glVertex3f(0.6,-0.5,-3.0);
        // change color
        glColor3f(0.0,0.0,1.0);
        // set point
        glVertex3f(0.7,0.5,-3.0);
    }
    glEnd();
    // Flush the buffer 
    glFlush();             
}

void reshapeFunc(int x, int y)
{
    
    if 
(== 0 || x == 0) return;  

    
//New projection matrix.
    glMatrixMode(GL_PROJECTION);  
    
//Load Identity matrix.
    glLoadIdentity();
    //Angle of view:40 degrees
    //Near clipping plane distance: 0.5
    //Far clipping plane distance: 20.0
    gluPerspective(40.0,(GLdouble)x/(GLdouble)y,0.5,20.0);
    glMatrixMode(GL_MODELVIEW);
    //Use all window size for rendering
    glViewport(0,0,x,y);  
}

int main(int argc, char *argv[])
{
    //Initialization to GLUT
    glutInit(&argc, argv);
    // Single Buffer
    // Use RGB Colors
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    // Set the width and height of windows
    glutInitWindowSize(400,400);
    // Create the window / with title = codemiles openGL
    glutCreateWindow("codemiles openGL");
    glClearColor(0.0,0.0,0.0,0.0);
    //Set the function used for display call back .
    glutDisplayFunc(displayFunc);
    //Set the function used for reshape call back .
    glutReshapeFunc(reshapeFunc);

    //start glut map
    glutMainLoop();
    return 0;
}
 


Attachments:
opengl.GIF
opengl.GIF [ 14.5 KiB | Viewed 460 times ]

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 pascal triangle
 Drawing Torus using OpenGL
 Drawing cone using openGL
 Drawing Octahedron using openGL
 Drawing and rotating Tetrahedron with animation
 Drawing teapot using OpenGL.
 drawing a rotating sphere
 two Different background colors
 drawing the histogram of image
 Table Border Colors for PHPBB3

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team