Total members 11894 |It is currently Fri Nov 22, 2024 10:40 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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 9260 times ]

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada
Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Drawing a triangle with colors
 pascal triangle     -  
 Triangle of stars (C++)     -  
 Draw Triangle using Lines     -  
 Java Programming Problem: Pascal's Triangle     -  
 Uneven rows-2-dimenstionals-triangle look like 2D array     -  
 two Different background colors     -  
 deal with colors in java     -  
 show Rainbow Colors     -  
 different colors for table Even- Odd rows and Cells     -  
 Making Colors Transparent with imagecolortransparent()     -  



Topic Tags

C++ Graphics
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com