دوست عزیز، به سایت علمی نخبگان جوان خوش آمدید

مشاهده این پیام به این معنی است که شما در سایت عضو نیستید، لطفا در صورت تمایل جهت عضویت در سایت علمی نخبگان جوان اینجا کلیک کنید.

توجه داشته باشید، در صورتی که عضو سایت نباشید نمی توانید از تمامی امکانات و خدمات سایت استفاده کنید.
صفحه 2 از 14 نخستنخست 123456789101112 ... آخرینآخرین
نمایش نتایج: از شماره 11 تا 20 , از مجموع 137

موضوع: برنامه هایی گرافیكی ( OpenGL )

  1. #11
    مدیر کـــــــل ســــایت
    رشته تحصیلی
    مهندسی کامپیوتر - نرم افزار
    اکانت شخصی
    ندارد
    نوشته ها
    7,883
    ارسال تشکر
    9,788
    دریافت تشکر: 29,042
    قدرت امتیاز دهی
    13974
    Array
    Admin's: جدید39

    پیش فرض

    اینم برنامه ای دیگه برای ساخت یك سری منحنی مانند خروجی ...

    کد:
    // mk.cpp : Defines the entry point for the console application.
    //
    #include "stdafx.h"
    #include <windows.h> // use proper includes for your system
    #include <math.h>
    #include <gl/Gl.h>
    #include <gl/glut.h>
    const int screenWidth = 640;       // width of screen window in pixels 
    const int screenHeight = 480;       // height of screen window in pixels
    GLdouble A, B, C, D;  // values used for scaling and shifting
    //<<<<<<<<<<<<<<<<<<<<<<< myInit >>>>>>>>>>>>>>>>>>>>
     void myInit(void)
     {
        glClearColor(0.0,0.0,0.0,1.0);       // background color is white
        glColor3f(0.0f, 0.0f, 0.0f);         // drawing color is black 
           glPointSize(2.0);                  // a 'dot' is 2 by 2 pixels
          glMatrixMode(GL_PROJECTION);        // set "camera shape"
          glLoadIdentity();
          gluOrtho2D(0.0, (GLdouble)screenWidth, 0.0, (GLdouble)screenHeight);
             A = screenWidth / 4.0; // set values used for scaling and shifting
             B = 0.0;
             C = D = screenHeight / 2.0;
    }
    //<<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>
    void myDisplay(void)
    {
        glClear(GL_COLOR_BUFFER_BIT);     // clear the screen 
        glBegin(GL_POINTS);
        glColor3f(1.0,1.0,0.0);
    
        for(GLdouble x = 0; x < 4.0 ; x += 0.005)
      {    
        GLdouble   func = sin(5*x)* 0.5 /5*x; 
         glVertex2f(A * x / 2 + B , C * func + D+125);
             }
    
    /*    for(GLdouble x = 0; x < 4.0 ; x += 0.005)
      {    
        GLdouble   func = sin(5*x)* 0.5 /5*x; 
         glVertex2f(A * x / 1+B, C * func + 1.5*D);
             } */
        glColor3f(0.0,0.9,0.0);
    
    for(GLdouble x = 0; x < 4.0 ; x += 0.005)
      {    
        GLdouble   func = cos(5 * x)* 0.5 / 5 * x; 
         glVertex2f(A * x  / 2 + B, C * func + D+125);
             }
    glColor3f(0.9,0.0,0.0);
    
    for(GLdouble x = 0; x < 4.0 ; x += 0.005)
      {    
        GLdouble   func = cos(5 * x)* 0.5 / 5 * x; 
         glVertex2f(A * x   / 2 + B + 15, C * func + D+125);
             }
    glColor3f(0.0 , 0.0 , 0.9);
    
    for(GLdouble x = 0; x < 4.0 ; x += 0.005)
      {    
        GLdouble   func = sin(5*x)* 0.5 /5*x; 
         glVertex2f(A * x / 2 + B + 15, C * func + D+125);
             }
    //------------------------------------------------------
    
        glColor3f(1.0,1.0,1.0);
    
        for(GLdouble x = 0; x < 4.0 ; x += 0.005)
      {    
        GLdouble   func = sin(5*x)* 0.5 /5*x; 
         glVertex2f(A * x / 2 + B , C * func + D-125);
             }
    
    
        glColor3f(0.0,0.9,0.5);
    
    for(GLdouble x = 0; x < 4.0 ; x += 0.005)
      {    
        GLdouble   func = cos(5 * x)* 0.5 / 5 * x; 
         glVertex2f(A * x  / 2 + B, C * func + D-125);
             }
    glColor3f(0.5,0.0,0.9);
    
    for(GLdouble x = 0; x < 4.0 ; x += 0.005)
      {    
        GLdouble   func = cos(5 * x)* 0.5 / 5 * x; 
         glVertex2f(A * x   / 2 + B + 15, C * func + D-125);
             }
    glColor3f(0.9 , 0.0 , 0.9);
    
    for(GLdouble x = 0; x < 4.0 ; x += 0.005)
      {    
        GLdouble   func = sin(5*x)* 0.5 /5*x; 
         glVertex2f(A * x / 2 + B + 15, C * func + D-125);
             }
        glEnd();    
        glFlush();           // send all output to display 
    }
    //<<<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>>
    void main(int argc, char** argv)
    {
        glutInit(&argc, argv);          // initialize the toolkit
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set display mode
        glutInitWindowSize(screenWidth, screenHeight); // set window size
        glutInitWindowPosition(100, 150); // set window position on screen
        glutCreateWindow("Dot Plot of a Function"); // open the screen window
        glutDisplayFunc(myDisplay);     // register redraw function
        myInit();                   
        glutMainLoop();              // go into a perpetual loop
    }
    خروجی برنامه:

    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

  2. کاربرانی که از پست مفید Admin سپاس کرده اند.


  3. #12
    مدیر کـــــــل ســــایت
    رشته تحصیلی
    مهندسی کامپیوتر - نرم افزار
    اکانت شخصی
    ندارد
    نوشته ها
    7,883
    ارسال تشکر
    9,788
    دریافت تشکر: 29,042
    قدرت امتیاز دهی
    13974
    Array
    Admin's: جدید39

    پیش فرض

    اینم یه برنامه ای پرچم ایران به همراه یه پاكت نامه درست می كنه ..!

    کد:
    // M3.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <windows.h>   // use as needed for your system
    #include <gl/Gl.h>
    #include <gl/glut.h>
    //<<<<<<<<<<<<<<<<<<<<<<< myInit >>>>>>>>>>>>>>>>>>>>
     void myInit(void)
     {
        glClearColor(1.0,1.0,1.0,0.0);       // set white background color
        glColor3f(0.0f, 0.0f, 0.0f);          // set the drawing color 
         glPointSize(4.0);               // a ‘dot’ is 4 by 4 pixels
        glMatrixMode(GL_PROJECTION); 
        glLoadIdentity();
        gluOrtho2D(0.0, 640.0, 0.0, 480.0);
    }
    //<<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>
    void myDisplay(void)
    {
        glClear(GL_COLOR_BUFFER_BIT);     // clear the screen
    
    // ---------------- back ground -------------------------
    
        glBegin(GL_POLYGON);
    
    glVertex2i(200, 600);
    glVertex2i(205, 600);
    glVertex2i(205, 0);
    glVertex2i(200, 0);
    
    glEnd();
    
    
    glBegin(GL_POLYGON);
    glColor3f(0.0f, 0.5f, 0.9f);
    glVertex2i(205, 600);
    glVertex2i(800, 600);
    glVertex2i(800, 0);
    glVertex2i(205, 0);
    
    glEnd();
    
    
    
    //----------------------------------------------------------
    
    
    
    
        glBegin(GL_POLYGON);
    glColor3f(0.0f, 0.0f, 0.9f);
            glVertex2i(50, 50);         
        glColor3f(0.0f, 0.9f, 0.0f);
            glVertex2i(50, 200);
    glColor3f(0.9f, 0.0f, 0.0f);
            glVertex2i(200, 50);
    glColor3f(0.9f, 0.0f, 0.0f);
            glVertex2i(200, 200);
    
    //--------------------------------------------------
    
            glColor3f(0.0f, 0.0f, 0.9f);
            glVertex2i(200, 200);         
        glColor3f(1.0f, 1.0f, 0.0f);
            glVertex2i(200, 50);
    glColor3f(0.9f, 0.0f, 0.0f);
            glVertex2i(50, 200);
    glColor3f(0.9f, 0.0f, 0.0f);
            glVertex2i(200, 200);
    
    glEnd();
    //---------------------------------------------------
    //---------------------------------------------------
    glBegin(GL_POLYGON);
    
     
    
    //--------------------------------------------------
    
            glColor3f(0.9f, 0.0f, 0.0f);
        
            glVertex2i(50, 200);         
    
            glColor3f(0.0f, 0.0f, 0.9f);
            
        glVertex2i(50, 350);
    
    glColor3f(1.0f, 1.0f, 0.0f);
    
    
            glVertex2i(200, 200);
    glVertex2i(50, 200);
            
    
    //-------------------------------------
    
    glColor3f(0.0f, 0.9f, 0.0f);
            glVertex2i(200, 350);        
        glColor3f(0.0f, 0.0f, 0.9f);
            glVertex2i(200, 200);
    glColor3f(0.9f, 0.0f, 0.0f);
            glVertex2i(50, 350);
    glColor3f(1.0f, 1.0f, 0.0f);
            glVertex2i(200, 350);
    
    
            //-------------------------
            glColor3f(0.0f, 0.9f, 0.0f);
            glVertex2i(50, 200);         
        glColor3f(0.0f, 0.0f, 0.9f);
            glVertex2i(50, 350);
    glColor3f(0.9f, 0.0f, 0.0f);
            glVertex2i(200, 200);
    
    glEnd();
    
    // ****************************** parcham ******************************
    
        glColor3f(0.0f, 0.0f, 0.0f);    
        glBegin(GL_POINTS);
    
    int qx=227;
    int qy=302;
    
    for(int i=0; i <350 ; i++){
            glVertex2i(qx, qy);
    
            qx++;
            qy;
    }
    
    for(int i=0; i <179 ; i++){
            glVertex2i(qx, qy);
    
            qx;
            qy--;
    }
    
    for(int i=0; i <354 ; i++){
            glVertex2i(qx, qy);
    
            qx--;
            qy;
    }
    
    
    for(int i=0; i <180 ; i++){
            glVertex2i(qx, qy);
    
            qx;
            qy++;
    }
    
        glEnd();
    
        //---------------------- plygon GREEN ----------------------------
    glColor3f(0.0f, 0.9f, 0.0f);
    glBegin(GL_POLYGON);
    
    glVertex2i(225, 300);
    
    glColor3f(0.5f, 0.9f, 0.5f);
    
    glVertex2i(575, 300);
    glVertex2i(575,245);
    
    glColor3f(0.0f, 0.9f, 0.0f);
    
    glVertex2i(225, 245);
    
    glEnd();
    //-------------------------polygon white -------------------------------
    glColor3f(1.0f, 1.0f, 1.0f);
    glBegin(GL_POLYGON);
    glVertex2i(225, 245);
    glVertex2i(575,245);
    
    glVertex2i(575, 180);
    glVertex2i(225, 180);
    glEnd();
    
    
    
    //------------------------polygon red --------------------
    
    glColor3f(0.9f, 0.0f, 0.0f);
    glBegin(GL_POLYGON);
    
    glVertex2i(225, 180);
    
    glColor3f(0.9f, 0.5f, 0.5f);
    
    glVertex2i(575, 180);
    glVertex2i(575, 125);
    
    glColor3f(0.9f, 0.0f, 0.0f);
    
    
    glVertex2i(225, 125);
    glEnd();
    // ---------------------- mileye parcham ------------------
    glBegin(GL_POLYGON);
    glColor3f(0.5f, 0.25f, 0.25f);
    
    
    glVertex2i(578, 308);
    glColor3f(0.68f, 0.37f, 0.37f);
    
    glVertex2i(587, 308);
    glVertex2i(587,0);
    
    glColor3f(0.5f, 0.25f, 0.25f);
    glVertex2i(578,0);
    
    
    
    
    glEnd();
    
    //----------------------------- allah ---------------------------
    
    
    glColor3f(0.0f, 0.0f, 0.0f);
    glBegin(GL_POINTS);
    
    
    qx= 412;
    qy = 230;
    
    for( int i=0; i<12 ; i++){
    
    glVertex2i(qx, qy);
    
    qx++;
    qy--;
    }
    
    for( int i=0; i<22 ; i++){
    
    glVertex2i(qx, qy);
    
    qx;
    qy--;
    }
    
    for( int i=0; i<12 ; i++){
    
    glVertex2i(qx, qy);
    
    qx--;
    qy--;
    }
    
    
    
    //****
    
    qx= 398;
    qy = 230;
    
    for( int i=0; i<12 ; i++){
    
    glVertex2i(qx, qy);
    
    qx++;
    qy--;
    }
    
    for( int i=0; i<22 ; i++){
    
    glVertex2i(qx, qy);
    
    qx;
    qy--;
    }
    
     for( int i=0; i<5 ; i++){
    
    glVertex2i(qx, qy);
    
    qx--;
    qy--;
    }
    
    glVertex2i(404, 191);
    glVertex2i(403, 190);
    glVertex2i(402, 190);
    glVertex2i(401, 189);
    glVertex2i(400, 189);
    glVertex2i(399, 188);
    glVertex2i(398, 188);
    glVertex2i(397, 187);
    glVertex2i(396, 187);
    glVertex2i(395, 186);
    glVertex2i(394, 186);
    glVertex2i(393, 185);
    glVertex2i(392, 185);
    glVertex2i(391, 184);
    glVertex2i(390, 184);
    
    glVertex2i(389, 183);
    glVertex2i(388, 183);
    
    
    glVertex2i(387, 182);
    glVertex2i(386, 182);
    glVertex2i(385, 181);
    glVertex2i(384, 181);
    
    glVertex2i(383, 181);
    glVertex2i(383, 181);
    
    glVertex2i(382, 181);
    glVertex2i(382, 181);
    
    
    glVertex2i(381, 181);
    glVertex2i(381, 181);
    
    //--------------------------------------------
    
    qx= 391;
    qy = 230;
    
    for( int i=0; i<50 ; i++){
    
    glVertex2i(qx, qy);
    
    qx;
    qy--;
    }
    
    //--------------------------------------------
    
    qx= 384;
    qy = 230;
    
    for( int i=0; i<12 ; i++){
    
    glVertex2i(qx, qy);
    
    qx--;
    qy--;
    }
    for( int i=0; i<22 ; i++){
    
    glVertex2i(qx, qy);
    
    qx;
    qy--;
    }
    
    
    for( int i=0; i<5 ; i++){
    
    glVertex2i(qx, qy);
    
    qx++;
    qy--;
    }
    
      
    qx=377;
    qy=191;
    
    glVertex2i(378, 191);
    glVertex2i(379, 190);
    glVertex2i(380, 190);
    glVertex2i(381, 189);
    glVertex2i(382, 189);
    glVertex2i(383, 188);
    glVertex2i(384, 188);
    glVertex2i(385, 187);
    glVertex2i(386, 187);
    glVertex2i(387, 186);
    glVertex2i(388, 186);
    glVertex2i(389, 185);
    glVertex2i(390, 185);
    glVertex2i(391, 184);
    glVertex2i(392, 184);
    
    glVertex2i(393, 183);
    glVertex2i(394, 183);
    
    glVertex2i(395, 182);
    glVertex2i(396, 182);
    
    glVertex2i(397, 181);
    glVertex2i(398, 181);
    
    glVertex2i(399, 181);
    glVertex2i(400, 181);
    
    glVertex2i(401, 181);
    glVertex2i(402, 181);
    
    //***
    
    qx=370;
    qy=230;
    
    for( int i=0; i<12 ; i++){
    
    glVertex2i(qx, qy);
    
    qx--;
    qy--;
    }
    for( int i=0; i<22 ; i++){
    
    glVertex2i(qx, qy);
    
    qx;
    qy--;
    }
    
    
    for( int i=0; i<12 ; i++){
    
    glVertex2i(qx, qy);
    
    qx++;
    qy--;
    }
    
    glVertex2i(398, 242);
    glVertex2i(398, 241);
    glVertex2i(398, 240);
    glVertex2i(398, 239);
    glVertex2i(398, 238);
    glVertex2i(397, 237);
    glVertex2i(396, 236);
    glVertex2i(395, 237);
    glVertex2i(394, 237);
    glVertex2i(393, 237);
    glVertex2i(392, 237);
    
    glVertex2i(392, 237);
    glVertex2i(392, 238);
    glVertex2i(392, 239);
    glVertex2i(392, 240);
    glVertex2i(392, 241);
    glVertex2i(392, 242);
    
    
    glVertex2i(391, 236);
    glVertex2i(390, 236);
    glVertex2i(389, 236);
    glVertex2i(388, 236);
    
    
    glVertex2i(387, 237);
    glVertex2i(386, 238);
    
    glVertex2i(386, 239);
    glVertex2i(386, 240);
    glVertex2i(386, 241);
    glVertex2i(386, 242);
    
    
    
    glEnd();
    
    
    // ----------------------  Text ( zende ) ------------------------------
    
    glBegin(GL_POINTS);
    
    glVertex2d(550,70);
    glVertex2d(551,70);
    glVertex2d(551,69);
    glVertex2d(550,69);
    
    int px = 555;
    int py = 55;
    
    
    for( int i=0;i<15;i++){
        glVertex2f(px,py);
        py--;
        
    }
    
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        py--;
    }
    
    for( int i=0;i<25;i++){
        glVertex2f(px,py);
        py--;
        px--;
    }
    
    px = 535;
    py = 65;
    
    
    for( int i=0;i<30;i++){
        glVertex2f(px,py);
        py--;
    }
    
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        px--;
        py--;
    }
    
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        px--;
    }
    
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        py++;
        px--;
    }
    
    
    for( int i=0;i<20;i++){
        px++;
        py--;
    }
    
    
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        py--;
        px--;
    }
    
    glVertex2f(510,70);
    glVertex2f(511,70);
    glVertex2f(511,69);
    glVertex2f(510,69);
    
    
    // ------------------ heeeeeeeeeeee ----------------------
    
    glVertex2f(470,38);
    
    px=470;
    py=38;
    for( int i=0;i<10;i++){
        glVertex2f(px,py);
        py--;
        px++;
    }
    
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        py--;
        
    }
    
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        py--;
        px--;
    }
    
    for( int i=0;i<10;i++){
        glVertex2f(px,py);
        px--;
        
    }
    for( int i=0;i<10;i++){
        glVertex2f(px,py);
        py++;
        
    }
    
    for( int i=0;i<7;i++){
        glVertex2f(px,py);
        py++;
        px++;
    }
    
    // ----------------------- text ( baaaad) --------------------
    px = 450;
    py = 35;
    
    for( int i=0;i<10;i++){
        glVertex2f(px,py);
        py--;
        
    }
    
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        py--;
        px--;
    }
    
    for( int i=0;i<30;i++){
        glVertex2f(px,py);
        px--;
        
    }
    
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        py++;
        px--;
    }
    
    for( int i=0;i<40;i++){
        glVertex2f(px,py);
        py++;
        
    }
    glVertex2f(430,10);
    glVertex2f(430,9);
    glVertex2f(429,9);
    glVertex2f(430,10);
    
    px = 395;
    py = 30;
    
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        py++;
        px--;
    }
    for( int i=0;i<20;i++){
        py--;
        px++;
    }
    
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        py--;
        px--;
    }
    
    // ------------------------ text ( iran ) ----------------------------
    
    px = 340;
    py = 80;
    
    for( int i=0;i<60;i++){
        glVertex2f(px,py);
        
        py--;
    }
    
    // ---------------------------------- ---- -------------------------------
    
    px = 320;
    py = 50;
    
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        
        py--;
    }
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        px--;
        py--;
    }
    
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        px--;
        
    }
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        px--;
        py--;
    }
    
    
    px = 315;
    py = 10;
    
    for( int i=0;i<10;i++){
        glVertex2f(px,py);
        px--;
        
    }
    
    
    px = 270;
    py = 75;
    
    for( int i=0;i<55;i++){
        glVertex2f(px,py);
    
        py--;
    }
    
    px = 250 ;
    py = 40 ;
    
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        
        py--;
    }
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        px--;
        py--;
    }
    
    for( int i=0;i<15;i++){
        glVertex2f(px,py);
        px--;
        
    }
    
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        px--;
        py++;
    }
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        py++;
    }
    
    glVertex2f(239,40);
    glVertex2f(238,40);
    glVertex2f(238,41);
    glVertex2f(239,41);
    
    
    
    glEnd();
    
        glFlush();                         // send all output to display 
    }
    
    //<<<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>>
    void main(int argc, char** argv)
    {
        glutInit(&argc, argv);          // initialize the toolkit
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set display mode
        glutInitWindowSize(640,480);     // set window size
        glutInitWindowPosition(100, 150); // set window position on screen
        glutCreateWindow("my first attempt"); // open the screen window
        glutDisplayFunc(myDisplay);     // register redraw function
        myInit();                   
        glutMainLoop();              // go into a perpetual loop
    }
    خروجی برنامه :

    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

  4. کاربرانی که از پست مفید Admin سپاس کرده اند.


  5. #13
    مدیر کـــــــل ســــایت
    رشته تحصیلی
    مهندسی کامپیوتر - نرم افزار
    اکانت شخصی
    ندارد
    نوشته ها
    7,883
    ارسال تشکر
    9,788
    دریافت تشکر: 29,042
    قدرت امتیاز دهی
    13974
    Array
    Admin's: جدید39

    پیش فرض

    این برنامه همین برنامه ی قبلیه كه پرچم رو با استفاده از كلمه ی مقدس الله اكبر Stipple کردم.

    کد:
    // M3.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <windows.h>   // use as needed for your system
    #include <gl/Gl.h>
    #include <gl/glut.h>
    //<<<<<<<<<<<<<<<<<<<<<<< myInit >>>>>>>>>>>>>>>>>>>>
     void myInit(void)
     {
        glClearColor(1.0,1.0,1.0,0.0);       // set white background color
        glColor3f(0.0f, 0.0f, 0.0f);          // set the drawing color 
         glPointSize(4.0);               // a ‘dot’ is 4 by 4 pixels
        glMatrixMode(GL_PROJECTION); 
        glLoadIdentity();
        gluOrtho2D(0.0, 640.0, 0.0, 480.0);
    }
    //<<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>
    void myDisplay(void)
    {
    
      GLubyte allah[] = {
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x0C, 0x60, 0x00, 0x00, 0x06, 0x60, 0x00, 0x20, 0x03, 0x00, 0x1F, 0xA0, 
        0x01, 0xF1, 0x12, 0xA0, 0x00, 0x31, 0x72, 0xA0, 0x00, 0x11, 0x72, 0xA0, 0x00, 0x11, 0x32, 0xA0, 
        0x00, 0x19, 0x00, 0xA0, 0x00, 0x0C, 0x00, 0x20, 0x00, 0x06, 0x0F, 0x80, 0x00, 0x02, 0x0A, 0x80, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    };
    
    
    
        glClear(GL_COLOR_BUFFER_BIT);     // clear the screen
    
    // ---------------- back ground -------------------------
    
        glBegin(GL_POLYGON);
    
    glVertex2i(200, 600);
    glVertex2i(205, 600);
    glVertex2i(205, 0);
    glVertex2i(200, 0);
    
    glEnd();
    
    
    glBegin(GL_POLYGON);
    glColor3f(1.0f, 1.0f, 1.0f);
    glVertex2i(205, 600);
    glVertex2i(800, 600);
    glVertex2i(800, 0);
    glVertex2i(205, 0);
    
    glEnd();
    
    
    
    //----------------------------------------------------------
    
    
    
    
        glBegin(GL_POLYGON);
    glColor3f(0.0f, 0.0f, 0.9f);
            glVertex2i(50, 50);         
        glColor3f(0.0f, 0.9f, 0.0f);
            glVertex2i(50, 200);
    glColor3f(0.9f, 0.0f, 0.0f);
            glVertex2i(200, 50);
    glColor3f(0.9f, 0.0f, 0.0f);
            glVertex2i(200, 200);
    
    //--------------------------------------------------
    
            glColor3f(0.0f, 0.0f, 0.9f);
            glVertex2i(200, 200);         
        glColor3f(1.0f, 1.0f, 0.0f);
            glVertex2i(200, 50);
    glColor3f(0.9f, 0.0f, 0.0f);
            glVertex2i(50, 200);
    glColor3f(0.9f, 0.0f, 0.0f);
            glVertex2i(200, 200);
    
    glEnd();
    //---------------------------------------------------
    //---------------------------------------------------
    glBegin(GL_POLYGON);
    
     
    
    //--------------------------------------------------
    
            glColor3f(0.9f, 0.0f, 0.0f);
        
            glVertex2i(50, 200);         
    
            glColor3f(0.0f, 0.0f, 0.9f);
            
        glVertex2i(50, 350);
    
    glColor3f(1.0f, 1.0f, 0.0f);
    
    
            glVertex2i(200, 200);
    glVertex2i(50, 200);
            
    
    //-------------------------------------
    
    glColor3f(0.0f, 0.9f, 0.0f);
            glVertex2i(200, 350);        
        glColor3f(0.0f, 0.0f, 0.9f);
            glVertex2i(200, 200);
    glColor3f(0.9f, 0.0f, 0.0f);
            glVertex2i(50, 350);
    glColor3f(1.0f, 1.0f, 0.0f);
            glVertex2i(200, 350);
    
    
            //-------------------------
            glColor3f(0.0f, 0.9f, 0.0f);
            glVertex2i(50, 200);         
        glColor3f(0.0f, 0.0f, 0.9f);
            glVertex2i(50, 350);
    glColor3f(0.9f, 0.0f, 0.0f);
            glVertex2i(200, 200);
    
    glEnd();
    
    // ****************************** parcham ******************************
    
        glColor3f(0.0f, 0.0f, 0.0f);    
        glBegin(GL_POINTS);
    
    int qx=227;
    int qy=302;
    
    for(int i=0; i <350 ; i++){
            glVertex2i(qx, qy);
    
            qx++;
            qy;
    }
    
    for(int i=0; i <179 ; i++){
            glVertex2i(qx, qy);
    
            qx;
            qy--;
    }
    
    for(int i=0; i <354 ; i++){
            glVertex2i(qx, qy);
    
            qx--;
            qy;
    }
    
    
    for(int i=0; i <180 ; i++){
            glVertex2i(qx, qy);
    
            qx;
            qy++;
    }
    
        glEnd();
    
        //---------------------- plygon GREEN ----------------------------
    glColor3f(0.0f, 0.9f, 0.0f);
    glBegin(GL_POLYGON);
    
    glVertex2i(225, 300);
    glColor3f(0.5f, 0.9f, 0.5f);
    glVertex2i(575, 300);
    glVertex2i(575,245);
    glColor3f(0.0f, 0.9f, 0.0f);
    glVertex2i(225, 245);
    
    glEnd();
    //------------------------- Polygon Stripple first allah --------------------------
     glEnable (GL_POLYGON_STIPPLE);
       glPolygonStipple (allah);
    glColor3f(0.0f, 0.0f, 0.0f);
    
    glBegin(GL_POLYGON);
    
    glVertex2i(225, 300);
    glVertex2i(575, 300);
    glVertex2i(575,255);
    glVertex2i(225, 255);
    
    glEnd();
    glDisable (GL_POLYGON_STIPPLE);
    
    //-------------------------polygon white -------------------------------
    glColor3f(1.0f, 1.0f, 1.0f);
    glBegin(GL_POLYGON);
    glVertex2i(225, 245);
    glVertex2i(575,245);
    
    glVertex2i(575, 180);
    glVertex2i(225, 180);
    glEnd();
    
    
    //------------------------polygon red --------------------
    
    glColor3f(0.9f, 0.0f, 0.0f);
    glBegin(GL_POLYGON);
    
    glVertex2i(225, 180);
    glColor3f(0.9f, 0.5f, 0.5f);
    glVertex2i(575, 180);
    glVertex2i(575, 125);
    glColor3f(0.9f, 0.0f, 0.0f);
    glVertex2i(225, 125);
    
    glEnd();
    
    
    //----------------------- polygon Striple second polygon -------------------
       glEnable (GL_POLYGON_STIPPLE);
       glPolygonStipple (allah);
    
    glColor3f(0.0f, 0.0f, 0.0f);
    glBegin(GL_POLYGON);
    
    glVertex2i(225, 160);
    glVertex2i(575, 160);
    glVertex2i(575, 125);
    glVertex2i(225, 125);
    
    
    glEnd();
    
    glDisable (GL_POLYGON_STIPPLE);
    
    
    
    // ---------------------- mileye parcham ------------------
    glBegin(GL_POLYGON);
    glColor3f(0.5f, 0.25f, 0.25f);
    
    
    glVertex2i(578, 308);
    glColor3f(0.68f, 0.37f, 0.37f);
    
    glVertex2i(587, 308);
    glVertex2i(587,0);
    
    glColor3f(0.5f, 0.25f, 0.25f);
    glVertex2i(578,0);
    
    
    
    
    glEnd();
    
    //----------------------------- allah ---------------------------
    
    
    glColor3f(0.0f, 0.0f, 0.0f);
    glBegin(GL_POINTS);
    
    
    qx= 412;
    qy = 230;
    
    for( int i=0; i<12 ; i++){
    
    glVertex2i(qx, qy);
    
    qx++;
    qy--;
    }
    
    for( int i=0; i<22 ; i++){
    
    glVertex2i(qx, qy);
    
    qx;
    qy--;
    }
    
    for( int i=0; i<12 ; i++){
    
    glVertex2i(qx, qy);
    
    qx--;
    qy--;
    }
    
    
    
    //****
    
    qx= 398;
    qy = 230;
    
    for( int i=0; i<12 ; i++){
    
    glVertex2i(qx, qy);
    
    qx++;
    qy--;
    }
    
    for( int i=0; i<22 ; i++){
    
    glVertex2i(qx, qy);
    
    qx;
    qy--;
    }
    
     for( int i=0; i<5 ; i++){
    
    glVertex2i(qx, qy);
    
    qx--;
    qy--;
    }
    
    glVertex2i(404, 191);
    glVertex2i(403, 190);
    glVertex2i(402, 190);
    glVertex2i(401, 189);
    glVertex2i(400, 189);
    glVertex2i(399, 188);
    glVertex2i(398, 188);
    glVertex2i(397, 187);
    glVertex2i(396, 187);
    glVertex2i(395, 186);
    glVertex2i(394, 186);
    glVertex2i(393, 185);
    glVertex2i(392, 185);
    glVertex2i(391, 184);
    glVertex2i(390, 184);
    
    glVertex2i(389, 183);
    glVertex2i(388, 183);
    
    
    glVertex2i(387, 182);
    glVertex2i(386, 182);
    glVertex2i(385, 181);
    glVertex2i(384, 181);
    
    glVertex2i(383, 181);
    glVertex2i(383, 181);
    
    glVertex2i(382, 181);
    glVertex2i(382, 181);
    
    
    glVertex2i(381, 181);
    glVertex2i(381, 181);
    
    //--------------------------------------------
    
    qx= 391;
    qy = 230;
    
    for( int i=0; i<50 ; i++){
    
    glVertex2i(qx, qy);
    
    qx;
    qy--;
    }
    
    //--------------------------------------------
    
    qx= 384;
    qy = 230;
    
    for( int i=0; i<12 ; i++){
    
    glVertex2i(qx, qy);
    
    qx--;
    qy--;
    }
    for( int i=0; i<22 ; i++){
    
    glVertex2i(qx, qy);
    
    qx;
    qy--;
    }
    
    
    for( int i=0; i<5 ; i++){
    
    glVertex2i(qx, qy);
    
    qx++;
    qy--;
    }
    
      
    qx=377;
    qy=191;
    
    glVertex2i(378, 191);
    glVertex2i(379, 190);
    glVertex2i(380, 190);
    glVertex2i(381, 189);
    glVertex2i(382, 189);
    glVertex2i(383, 188);
    glVertex2i(384, 188);
    glVertex2i(385, 187);
    glVertex2i(386, 187);
    glVertex2i(387, 186);
    glVertex2i(388, 186);
    glVertex2i(389, 185);
    glVertex2i(390, 185);
    glVertex2i(391, 184);
    glVertex2i(392, 184);
    
    glVertex2i(393, 183);
    glVertex2i(394, 183);
    
    glVertex2i(395, 182);
    glVertex2i(396, 182);
    
    glVertex2i(397, 181);
    glVertex2i(398, 181);
    
    glVertex2i(399, 181);
    glVertex2i(400, 181);
    
    glVertex2i(401, 181);
    glVertex2i(402, 181);
    
    //***
    
    qx=370;
    qy=230;
    
    for( int i=0; i<12 ; i++){
    
    glVertex2i(qx, qy);
    
    qx--;
    qy--;
    }
    for( int i=0; i<22 ; i++){
    
    glVertex2i(qx, qy);
    
    qx;
    qy--;
    }
    
    
    for( int i=0; i<12 ; i++){
    
    glVertex2i(qx, qy);
    
    qx++;
    qy--;
    }
    
    glVertex2i(398, 242);
    glVertex2i(398, 241);
    glVertex2i(398, 240);
    glVertex2i(398, 239);
    glVertex2i(398, 238);
    glVertex2i(397, 237);
    glVertex2i(396, 236);
    glVertex2i(395, 237);
    glVertex2i(394, 237);
    glVertex2i(393, 237);
    glVertex2i(392, 237);
    
    glVertex2i(392, 237);
    glVertex2i(392, 238);
    glVertex2i(392, 239);
    glVertex2i(392, 240);
    glVertex2i(392, 241);
    glVertex2i(392, 242);
    
    
    glVertex2i(391, 236);
    glVertex2i(390, 236);
    glVertex2i(389, 236);
    glVertex2i(388, 236);
    
    
    glVertex2i(387, 237);
    glVertex2i(386, 238);
    
    glVertex2i(386, 239);
    glVertex2i(386, 240);
    glVertex2i(386, 241);
    glVertex2i(386, 242);
    
    
    
    glEnd();
    
    
    // ----------------------  Text ( zende ) ------------------------------
    
    glBegin(GL_POINTS);
    
    glVertex2d(550,70);
    glVertex2d(551,70);
    glVertex2d(551,69);
    glVertex2d(550,69);
    
    int px = 555;
    int py = 55;
    
    
    for( int i=0;i<15;i++){
        glVertex2f(px,py);
        py--;
        
    }
    
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        py--;
    }
    
    for( int i=0;i<25;i++){
        glVertex2f(px,py);
        py--;
        px--;
    }
    
    px = 535;
    py = 65;
    
    
    for( int i=0;i<30;i++){
        glVertex2f(px,py);
        py--;
    }
    
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        px--;
        py--;
    }
    
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        px--;
    }
    
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        py++;
        px--;
    }
    
    
    for( int i=0;i<20;i++){
        px++;
        py--;
    }
    
    
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        py--;
        px--;
    }
    
    glVertex2f(510,70);
    glVertex2f(511,70);
    glVertex2f(511,69);
    glVertex2f(510,69);
    
    
    // ------------------ heeeeeeeeeeee ----------------------
    
    glVertex2f(470,38);
    
    px=470;
    py=38;
    for( int i=0;i<10;i++){
        glVertex2f(px,py);
        py--;
        px++;
    }
    
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        py--;
        
    }
    
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        py--;
        px--;
    }
    
    for( int i=0;i<10;i++){
        glVertex2f(px,py);
        px--;
        
    }
    for( int i=0;i<10;i++){
        glVertex2f(px,py);
        py++;
        
    }
    
    for( int i=0;i<7;i++){
        glVertex2f(px,py);
        py++;
        px++;
    }
    
    // ----------------------- text ( baaaad) --------------------
    px = 450;
    py = 35;
    
    for( int i=0;i<10;i++){
        glVertex2f(px,py);
        py--;
        
    }
    
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        py--;
        px--;
    }
    
    for( int i=0;i<30;i++){
        glVertex2f(px,py);
        px--;
        
    }
    
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        py++;
        px--;
    }
    
    for( int i=0;i<40;i++){
        glVertex2f(px,py);
        py++;
        
    }
    glVertex2f(430,10);
    glVertex2f(430,9);
    glVertex2f(429,9);
    glVertex2f(430,10);
    
    px = 395;
    py = 30;
    
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        py++;
        px--;
    }
    for( int i=0;i<20;i++){
        py--;
        px++;
    }
    
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        py--;
        px--;
    }
    
    // ------------------------ text ( iran ) ----------------------------
    
    px = 340;
    py = 80;
    
    for( int i=0;i<60;i++){
        glVertex2f(px,py);
        
        py--;
    }
    
    // ---------------------------------- ---- -------------------------------
    
    px = 320;
    py = 50;
    
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        
        py--;
    }
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        px--;
        py--;
    }
    
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        px--;
        
    }
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        px--;
        py--;
    }
    
    
    px = 315;
    py = 10;
    
    for( int i=0;i<10;i++){
        glVertex2f(px,py);
        px--;
        
    }
    
    
    px = 270;
    py = 75;
    
    for( int i=0;i<55;i++){
        glVertex2f(px,py);
    
        py--;
    }
    
    px = 250 ;
    py = 40 ;
    
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        
        py--;
    }
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        px--;
        py--;
    }
    
    for( int i=0;i<15;i++){
        glVertex2f(px,py);
        px--;
        
    }
    
    for( int i=0;i<5;i++){
        glVertex2f(px,py);
        px--;
        py++;
    }
    for( int i=0;i<20;i++){
        glVertex2f(px,py);
        py++;
    }
    
    glVertex2f(239,40);
    glVertex2f(238,40);
    glVertex2f(238,41);
    glVertex2f(239,41);
    
    
    
    glEnd();
    
        glFlush();                         // send all output to display 
    }
    
    //<<<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>>
    void main(int argc, char** argv)
    {
        glutInit(&argc, argv);          // initialize the toolkit
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set display mode
        glutInitWindowSize(640,480);     // set window size
        glutInitWindowPosition(100, 150); // set window position on screen
        glutCreateWindow("parcham"); // open the screen window
        glutDisplayFunc(myDisplay);     // register redraw function
        myInit();                   
        glutMainLoop();              // go into a perpetual loop
    }
    تصویر خروجی رو به عنوان پیوست آپلود کردم.
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

  6. #14
    مدیر کـــــــل ســــایت
    رشته تحصیلی
    مهندسی کامپیوتر - نرم افزار
    اکانت شخصی
    ندارد
    نوشته ها
    7,883
    ارسال تشکر
    9,788
    دریافت تشکر: 29,042
    قدرت امتیاز دهی
    13974
    Array
    Admin's: جدید39

    پیش فرض

    خب از این به بعد می ریم سر قرار دادن برنامه های انیمیشن و متحرك....

    این برنامه ی چینش دیواره كه در سیستم عامل های قدیمی به عنوان اسكرین سیور هم استفاده می شد.

    کد:
    #include "stdafx.h"
    #include <windows.h>   // use as needed for your system
    #include <gl/Gl.h>
    #include <gl/glut.h>
    int flag=0;
    int x1=0,y1=0,ystep=8,xstep=8,count=1,gap=1;
    void display()
        {
        switch(flag){ // Switch Flag For Changing Brick Color
            case 1:
                glColor3f(1.0f, 0.0f, 0.0f);
    break;
            case 2:
                glColor3f(0.0f, 1.0f, 0.0f);
        break;
    
            case 3:
                glColor3f(0.0f, 0.0f, 1.0f);
        break;
            case 4:
                glColor3f(1.0f, 1.0f, 0.0f);
        break;
            case 5:
                glColor3f(1.0f, 0.0f, 1.0f);
        break;
            case 6:
                glColor3f(1.0f, 0.5f, 0.0f);
        break;
            case 7:
                glColor3f(0.5f, 0.0f, 1.0f);
        break;
            case 8:
                glColor3f(1.0f, 1.0f, 0.0f);
        break;
            case 9:
                glColor3f(0.5f, 0.0f, 0.5f);
        break;
            case 10:
                glColor3f(0.0f, 1.0f, 1.0f);
        break;
    
            }
        glBegin(GL_POLYGON);
            glVertex2i(x1,y1);
            glVertex2i(x1,y1+ystep);
            glVertex2i(x1+xstep,y1+ystep);
            glVertex2i(x1+xstep,y1);
        glEnd();
        glFlush();
        }
    void myinit()
    {
        gluOrtho2D(100,0,0,300);
    }
    void TimerFunction(int value)
    {
        if(value!=1){                 //First BRICK  INCREASEING
            x1+=(xstep+gap);
        }
        else glClear(GL_COLOR_BUFFER_BIT); //For First Time Implementation Must Screen Was Black
        
    
        if(x1>100){                    
            y1=count*(ystep+2*gap);
            count++;
            if(count%2==0)x1=-5;
            else x1=0;
            flag++;
            if (flag == 10) flag = 0;
        } // if                            // //One Row Is Set
    
    
        if(y1>300){            //repeat wall
            y1=0;
            x1=0;
            count=0;
            glClear(GL_COLOR_BUFFER_BIT);
        } //if
        glutPostRedisplay();
        glutTimerFunc(50,TimerFunction,2);
    }                               // end TimerFunction
    void main()
    {
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
        glutCreateWindow("Mostafa Wall");
        glutInitWindowSize (640, 480);
        glutDisplayFunc(display);
        glutTimerFunc(60, TimerFunction,1);
        myinit();
        glutMainLoop();
    }
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

  7. #15
    مدیر کـــــــل ســــایت
    رشته تحصیلی
    مهندسی کامپیوتر - نرم افزار
    اکانت شخصی
    ندارد
    نوشته ها
    7,883
    ارسال تشکر
    9,788
    دریافت تشکر: 29,042
    قدرت امتیاز دهی
    13974
    Array
    Admin's: جدید39

    پیش فرض

    خب این برنامه برنامه ی گوی هایی است كه به شكلی به دور گوی دیگه ای می چرخند ..!

    کد:
    // Atom.c
    // OpenGL SuperBible, Chapter 5
    // Demonstrates OpenGL coordinate transformation
    // Program by Richard S. Wright Jr.
    #include "stdafx.h"
    #include <windows.h>
    #include <gl/gl.h>
    #include <gl/glu.h>
    #include <gl/glut.h>
    #include <math.h>
    
    
    
    
    // Rotation amounts
    static GLfloat xRot = 0.0f;
    static GLfloat yRot = 0.0f;
    
    
    // Called to draw scene
    void RenderScene(void)
    	{
    	// Angle of revolution around the nucleus
    	static float fElect1 = 0.0f;
    
    	// Clear the window with current clearing color
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    	// Reset the modelview matrix
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    
    	// Translate the whole scene out and into view
    	// This is the initial viewing transformation
    	glTranslatef(0.0f, 0.0f, -100.0f);
    
    	// Green Nucleus
    	glColor3ub(0, 255, 0);
    	glutSolidSphere(10.0f, 15, 15);
    
    	// Yellow Electron1
    	glColor3ub(0,0,255);
    
    	// First Electron Orbit //////////////////////////////////// Abi ///////////////////
    	// Save viewing transformation
    	glPushMatrix();
    
    	// Rotate by angle of revolution
    	glRotatef(fElect1, 1.0f, 0.0f, 0.0f);
    
    	// Translate out from origin to orbit distance
    	glTranslatef(90.0f, 30.0f, 0.0f);
    
    	// Draw the electron
    	glutSolidSphere(6.0f, 15, 15);
        
    
    	// Restore the viewing transformation
    	glPopMatrix();
    
    	glColor3ub(255,255,255);
    
    	// Second Electron Orbit //////////// sefid //////////////////////////////////
    	glPushMatrix();
    	glRotatef(0.0f, 1.0f, 0.0f, 0.0f);
    	glRotatef(fElect1, 0.0f, 1.0f, 0.0f);
    	glTranslatef(30.0f, 90.0f, 0.0f);
    	glutSolidSphere(6.0f, 15, 15);
    	glPopMatrix();
    
    // Second Electron Orbit //////////// narengi //////////////////////////////////
    	glColor3ub(255,128,0);
    	glPushMatrix();
    	glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
    	glRotatef(fElect1, 1.0f, 0.0f, 0.0f);
    	glTranslatef(30.0f, 0.0f - 90, 0.0f);
    	glutSolidSphere(6.0f, 15, 15);
    	glPopMatrix();
    
    // Second Electron Orbit //////////// narengi //////////////////////////////////
    	glColor3ub(255,128,0);
    	glPushMatrix();
    	glRotatef(0.0f, 1.0f, 0.0f, 0.0f);
    	glRotatef(fElect1, 1.0f, 0.0f, 0.0f);
    	glTranslatef(0.0f - 30, 0.0f - 90, 0.0f);
    	glutSolidSphere(6.0f, 15, 15);
    	glPopMatrix();
    
    
    	// Second Electron Orbit //////////// narengi y 1//////////////////////////////////
    	glColor3ub(255,128,0);
    	glPushMatrix();
    	glRotatef(0.0f, 0.0f, 1.0f, 0.0f);
    	glRotatef(fElect1, 0.0f, 1.0f, 0.0f);
    	glTranslatef(0.0f - 90, 0.0f - 30, 0.0f);
    	glutSolidSphere(6.0f, 15, 15);
    	glPopMatrix();
    
    
    	// Second Electron Orbit //////////// narengi y 1//////////////////////////////////
    	glColor3ub(255,128,0);
    	glPushMatrix();
    	glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
    	glRotatef(fElect1, 0.0f, 1.0f, 0.0f);
    	glTranslatef(0.0f - 90, 0.0f + 30, 0.0f);
    	glutSolidSphere(6.0f, 15, 15);
    	glPopMatrix();
    
    
    
    	glColor3ub(255,0,0); //////////////////////////////// ghermez /////////////////////
    
    		glPushMatrix();
    	glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
    	glRotatef(fElect1, 1.0f, 0.0f, 0.0f);
    	glTranslatef(0.0f - 90, 30.0f, 0.0f);
    	glutSolidSphere(6.0f, 15, 15);
    	glPopMatrix();
    
    
    	glColor3ub(255,255,0); // Second Electron Orbit //////////// zard //////////////////////////////////
    	glPushMatrix();
    	glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
    	glRotatef(fElect1, 0.0f, 1.0f, 0.0f);
    	glTranslatef(30.0f, 0.0f - 90, 0.0f);
    	glutSolidSphere(6.0f, 15, 15);
    	glPopMatrix();
    
    
    
    	// Increment the angle of revolution
    	fElect1 += 10.0f;
    	if(fElect1 > 360.0f)
    		fElect1 = 0.0f;
    
    	// Show the image
    	glutSwapBuffers();
    	}
    
    
    // This function does any needed initialization on the rendering
    // context. 
    void SetupRC()
    	{
    	glEnable(GL_DEPTH_TEST);	// Hidden surface removal
    	glFrontFace(GL_CCW);		// Counter clock-wise polygons face out
    	glEnable(GL_CULL_FACE);		// Do not calculate inside of jet
    
    	// Black background
    	glClearColor(0.0f, 0.0f, 0.0f, 1.0f );	
        }
    
    void SpecialKeys(int key, int x, int y)
    	{
    	if(key == GLUT_KEY_UP)
    		xRot-= 5.0f;
    
    	if(key == GLUT_KEY_DOWN)
    		xRot += 5.0f;
    
    	if(key == GLUT_KEY_LEFT)
    		yRot -= 5.0f;
    
    	if(key == GLUT_KEY_RIGHT)
    		yRot += 5.0f;
    
    	if(key > 356.0f)
    		xRot = 0.0f;
    
    	if(key < -1.0f)
    		xRot = 355.0f;
    
    	if(key > 356.0f)
    		yRot = 0.0f;
    
    	if(key < -1.0f)
    		yRot = 355.0f;
    
    	// Refresh the Window
    	glutPostRedisplay();
    	}
    
    void TimerFunc(int value)
        {
        glutPostRedisplay();
        glutTimerFunc(100, TimerFunc, 1);
        }
    
    
    void ChangeSize(int w, int h)
    	{
    	GLfloat nRange = 100.0f;
    
    	// Prevent a divide by zero
    	if(h == 0)
    		h = 1;
    
    	// Set Viewport to window dimensions
        glViewport(0, 0, w, h);
    
    
    	// Reset coordinate system
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    
    	// Establish clipping volume (left, right, bottom, top, near, far)
        if (w <= h) 
    		glOrtho (-nRange, nRange, nRange*h/w, -nRange*h/w, -nRange*2.0f, nRange*2.0f);
        else 
    		glOrtho (-nRange*w/h, nRange*w/h, nRange, -nRange, -nRange*2.0f, nRange*2.0f);
    
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
      	}
    
    int main(int argc, char* argv[])
    	{
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    	glutCreateWindow("OpenGL Atom");
    	glutReshapeFunc(ChangeSize);
    	glutSpecialFunc(SpecialKeys);
    	glutDisplayFunc(RenderScene);
        glutTimerFunc(500, TimerFunc, 1);
    	SetupRC();
    	glutMainLoop();
    
    	return 0;
    	}
    تصویر خروجی برنامه به همراه فایل اجرایی به عنوان فایل پیوست قرار دارد.
    موفق باشید
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

  8. #16
    مدیر کـــــــل ســــایت
    رشته تحصیلی
    مهندسی کامپیوتر - نرم افزار
    اکانت شخصی
    ندارد
    نوشته ها
    7,883
    ارسال تشکر
    9,788
    دریافت تشکر: 29,042
    قدرت امتیاز دهی
    13974
    Array
    Admin's: جدید39

    پیش فرض

    نمايش ساعت سيستم بصورت آنالوگ و ديجيتال
    اين برنامه در محيط سي ++ و با پسوند cpp هست.




    کد:
    //Programmed By : Himanshu Mishra
    //Email ID : himanshu_mishra007@yahoo.co.in
    /*Other Programmes: 1) SNAKEG
       2) PIANO
    */
    #include<graphics.h>
    #include<math.h>
    #include<conio.h>
    #include<dos.h>
    #include<stdlib.h>
    const float PI=3.141;
    class needle
     {
     int size,color,x,y,end_x,end_y;
     double theta;
    public:
     void draw(float,float);
     void init(int a,int b,int c,int d)
      {x=a;y=b;size=c;color=d;}
     };
    void needle::draw(float a,float b)
     {
     theta=(a*b-90)*(PI/180);
     setcolor(0);
     line(x,y,end_x,end_y);
     setcolor(color);
     end_x=x+cos(theta)*size;
     end_y=y+sin(theta)*size;
     line(x,y,end_x,end_y);
     }
    void main()
     {
     int d=DETECT,m;
     initgraph(&d,&m,"c:\\tc\\bgi");
    // setbkcolor(0);
     int size=90,a;
     float theta;
     char tim[12][3]={"3","4","5","6","7","8","9","10","11","12","1","2"};
     for(int i=0,j=0;i<360;i+=6)
      {
      theta=PI/180*i;
      a=3;
      if(i%5==0)
       {
       a=12;
       outtextxy(320+cos(theta)*(size-a)-textwidth(tim[j])/2,240+sin(theta)*(size-a)-textheight(tim[j])/2,tim[j]);
       j++;
       a=8;
       }
      line(320+cos(theta)*(size-a),240+sin(theta)*(size-a),320+cos(theta)*size,240+sin(theta)*size);
      }
     circle(320,240,size+2);
     circle(320,240,size+8);
     setfillstyle(1,LIGHTBLUE);
     floodfill(320,240+size+3,getcolor());
    // setfillstyle(1,6);
    // floodfill(0,0,getcolor());
     outtext("Press any key to exit......");
     needle second,minute,hour,milli;
     second.init(320,240,60,BLUE);
     minute.init(320,240,70,RED);
     hour.init(320,240,40,LIGHTGRAY);
     milli.init(320,240,65,6);
     int sec,min,hr,hun,last_hun;
     static char d_hr[3],d_min[3],d_sec[3],d_hun[3],time[20];
     int d_x=275,d_y=120;
     struct time t;
     while(!kbhit())
      {
      gettime(&t);
      hun=t.ti_hund;
      sec=t.ti_sec;
      min=t.ti_min;
      hr=t.ti_hour;
      if(hun!=last_hun)
       {
     //STARTING ANALOG CLOCK
       setcolor(getbkcolor());
       outtextxy(d_x,d_y,time);
       setlinestyle(0,0,1);
       milli.draw(hun,360/100);
       second.draw(sec*100+hun,0.06);
       setlinestyle(0,0,3);
       minute.draw(min*60+sec,0.1);
       hour.draw(hr*60+min,0.5);
     //ENDING ANALOG CLOCK
     //STARTING DIGITAL WATCH
       itoa(hr,d_hr,10);
       itoa(min,d_min,10);
       itoa(sec,d_sec,10);
       itoa(hun,d_hun,10);
       time[0]=d_hr[0];
       time[1]=d_hr[1];
       time[2]=':';
       time[3]=d_min[0];
       time[4]=d_min[1];
       time[5]=':';
       time[6]=d_sec[0];
       time[7]=d_sec[1];
       time[8]='.';
       time[9]=d_hun[0];
       time[10]=d_hun[1];
       for(int i=0;i<11;i++)
        if(time[i]=='\0'){time[i]=time[i-1];time[i-1]='0';}
       time[11]='\0';
       setcolor(random(15));
       outtextxy(d_x,d_y,time);
     //ENDING DIGITAL WATCH
       }
      last_hun=hun;
      }
     closegraph();
     }
    مشخصات نويسنده ي برنامه در متن برنامه آورده شده
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

  9. #17
    مدیر کـــــــل ســــایت
    رشته تحصیلی
    مهندسی کامپیوتر - نرم افزار
    اکانت شخصی
    ندارد
    نوشته ها
    7,883
    ارسال تشکر
    9,788
    دریافت تشکر: 29,042
    قدرت امتیاز دهی
    13974
    Array
    Admin's: جدید39

    پیش فرض

    مسابقه ماشين سواري

    ابتدا نام بازيكن رو وارد كرده و اينتر مي زنيد سپس وارد برنامه مي شويد...

    با استفاده از كليدهاي مكان نماي راست و چپ مي توانيد ماشين را حركت دهيد...

    در قسمت سمت راست صفحه نام و امتياز اولين بازيكن از ابتدايي كه بازي را برا اولين بار در سيستم خود اجرا كرديد تا كنون، را نمايش مي دهد نام و امتياز برنده در فايلي به نامhscore.txt در درايو سي ذخيره ميشود...

    کد:
    //**************************************
    // Name: Car Race
    // Description:It have no complexities, very simple to understand, and it shows that you can make impressive program by using simple beginner coding.
    // By: CppKid
    //
    //
    // Inputs:None
    //
    // Returns:None
    //
    //Assumes:Just set the path for bgi directory.
    //
    //Side Effects:None
    //This code is copyrighted and has limited warranties.
    //Please see http://www.planet-source-code.com/xq...s/ShowCode.htm
    //for details.
    //**************************************
    کد:
    #include<graphics.h>
    #include<fstream.h>
    #include<conio.h>
    #include<iostream.h>
    #include<stdlib.h>
    #include<dos.h>
    #define b setfillstyle(1,1)
    #define n setfillstyle(1,0)
    #define r setfillstyle
    int x=270,cha=10,sp=6;
    struct hs
    
        {
        char name[30];
        int ad;
    };
    ifstream pt;
    void burn()
    
        {
        setcolor(14);
        circle(x-20,451,4);
        circle(x-18,451,4);
        circle(x-16,451,5);
        circle(x-14,451,6);
        circle(x-12,451,6);
        circle(x-10,451,5);
        circle(x-8,451,6);
        circle(x-38,451,4);
        circle(x-36,451,5);
        circle(x-34,451,5);
        circle(x-22,451,5);
        circle(x-24,451,5);//Burn
        circle(x-26,451,4);
        circle(x-28,451,4);
        circle(x-30,451,6);
        circle(x-32,451,6);
        setcolor(4);
        circle(x-19,450,6);
        circle(x-17,450,5);
        circle(x-15,450,5);
        circle(x-13,450,6);
        circle(x-11,450,6);
        circle(x-9,450,5);
        circle(x-37,450,4);
        circle(x-35,450,5);
        circle(x-33,450,6);
        circle(x-31,450,6);//Burn
        circle(x-21,450,5);
        circle(x-23,450,5);
        circle(x-25,450,4);
        circle(x-27,450,4);
        circle(x-29,450,4);
        setcolor(14);
        circle(x-20,461,4);
        circle(x-18,461,4);
        circle(x-16,461,5);
        circle(x-14,461,6);
        circle(x-12,461,6);
        circle(x-10,461,5);
        circle(x-8,461,6);
        circle(x-38,461,4);
        circle(x-36,461,5);
        circle(x-34,461,5);
        circle(x-22,461,5);
        circle(x-24,461,5);
        circle(x-26,461,4);
        circle(x-28,461,4);
        circle(x-30,461,6);
        circle(x-32,461,6);
        setcolor(4);
        circle(x-19,460,6);
        circle(x-17,460,5);
        circle(x-15,460,5);
        circle(x-13,460,6);
        circle(x-11,460,6); //Burn
        circle(x-9,460,5);
        circle(x-37,460,4);
        circle(x-35,460,5);
        circle(x-33,460,6);
        circle(x-31,460,6);
        circle(x-21,460,5);
        circle(x-23,460,5);
        circle(x-25,460,4);
        circle(x-27,460,4);
        circle(x-29,460,4);
    }
    ofstream ptr;
    void main(void)
    
        {
        clrscr();
        hs rea,wri;
        cout<<" Enter name = ";
        cin.getline(wri.name,30);
        int as=0;
        int DRIVER= DETECT,MODE;
        MODE=2;
        DRIVER=9;
        initgraph(&DRIVER, &MODE,"c:\\tc\\bgi");
        pt.open("c:\\hscore.txt",ios::in);
        if(pt)
        pt.read((signed char *)(&rea),sizeof(hs));
        if(!pt)
    
            {
            rea.name[0]=0;
            rea.ad=0;
        }
        pt.close();
        ptr.open("c:\\hscore.txt",ios::out);
    
            {
            setcolor(8);
            line(300,190,200,500);
            line(400,190,500,500);
            line(302,190,202,500);
            line(402,190,502,500);
            setcolor(7); //road
            line(298,190,198,500);
            line(300,190,200,500);
            line(402,190,502,500);
            line(404,190,504,500);
            setcolor(10);
            line(292,190,192,500);
            line(294,190,194,500);
            line(408,190,508,500);
            line(410,190,510,500);
            line(282,190,182,500);
            line(284,190,184,500);
            line(286,190,186,500);
            line(288,190,188,500); //green road
            line(414,190,514,500);
            line(416,190,516,500);
            line(420,190,520,500);
            line(422,190,522,500);
            r(1,9);
            bar(0,0,650,190);
            setcolor(14);
            circle(100,50,1);
            circle(100,50,2);
            circle(100,50,3);
            circle(100,50,4);
            circle(100,50,5);
            circle(100,50,6);
            circle(100,50,7);
            circle(100,50,8);
            circle(100,50,9);
            circle(100,50,10); //sun
            circle(100,50,11);
            circle(100,50,12);
            circle(100,50,13);
            circle(100,50,14);
            circle(100,50,15);
            circle(100,50,16);
            circle(100,50,17);
            circle(100,50,18);
            int x=270;
            b;
            bar(x,457,x-50,468);
            r(1,4);
            bar(x-30,457,x-50,465);
            bar(x,457,x-20,465);
            r(8,6);//Car
            bar(x-40,459,x-10,463);
            r(8,14);
            bar(x-40,463,x-10,464);
            setcolor(0);
            circle(x-5,460,3);
            circle(x-5,460,2); //Cylencer
            circle(x-5,460,1);
            r(1,8);
            bar(x-2,465,x-8,472);
            bar(x-48,465,x-42,472);
            setcolor(2);
            line(x-2,457,x-8,447); //Car tyre & roof
            line(x-50,457,x-42,447);
            line(x-42,447,x-8,447);
            r(1,14);
            pieslice(100,50,300,50,18);
            pieslice(100,50,0,99,18);
            pieslice(100,50,-20,624,18);
        }
        char a;
        int o,l,m,c,p,t,q,w;
        o=270;
        l=200;
        m=80;
        c=315;
        p=200;
        q=205;
        t=310;
        w=350;
        int ene=21;
        float sd=0;
        gotoxy(2,19);
        cout<<"Name = "<<wri.name<<"\n Score = ";
        setcolor(9);
        settextstyle(5,0,2);
        outtextxy(20,415,"Energy");
        setcolor(6);
        rectangle(19,461,123,449);
        rectangle(20,460,122,450);
        settextstyle(7,0,2);
        outtextxy(440,190,"HIGHEST SCORE ");
        gotoxy(58,16);
        cout<<"Name = "<<rea.name;
        gotoxy(58,17);
        cout<<"Score = "<<rea.ad;
        setcolor(14);
        rectangle(520,430,620,440);
        setfillstyle(1,9);
        bar(521,431,559,439);
        outtextxy(521,400,"Speed");
        for(int i=0;sd<=4500;i++)
    
            {
            if(a=='e')
    
                {
                wri.ad=as;
                if (rea.ad>wri.ad)
                ptr.write((signed char *)(&rea),sizeof(hs));
                else
                ptr.write((signed char *)(&wri),sizeof(hs));
                ptr.close();
                burn();
                closegraph();
                exit(1);
                sd=4500;
            }
            if (a=='a')
    
                {
                setfillstyle(1,0);
                bar(521,431,619,439);
                setfillstyle(1,13);
                bar(521,431,539,439);
                sp=5;
            }
            if (a=='s')
    
                {
                setfillstyle(1,0);
                bar(521,431,619,439);
                setfillstyle(1,9);
                bar(521,431,559,439);
                sp=6;
            }
            if (a=='d')
    
                {
                sp=7;
                setfillstyle(1,0);
                bar(521,431,619,439);
                setfillstyle(1,11);
                bar(521,431,579,439);
            }
            if (a=='f')
    
                {
                setfillstyle(1,0);
                bar(521,431,619,439);
                setfillstyle(1,10);
                bar(521,431,599,439);
                sp=8;
            }
            if (a=='g')
    
                {
                setfillstyle(1,0);
                bar(521,431,619,439);
                setfillstyle(1,4);
                bar(521,431,619,439);
                sp=9;
            }
            while(!kbhit())
    
                {
                delay(22);
                sd++;
                gotoxy(9,20);
                cout<<as;
                gotoxy(2,16);
                setcolor(1);
                setfillstyle(1,0);
                rectangle(1,184,637,188);
                rectangle(2,183,638,189);
                bar(3,185,sd/7,187);
                l=l+18; //while
                m=m-1;
                p=p+sp;
                q=q+sp-2;
                r(1,15);
                bar(347,l,353,l+40);
                r(1,8);
                circle(t,p,8);
                setcolor(0);
                circle(t,p-sp,8);
                if(p>455)//Khadday
                if(t>x-50)
                if(t<x)
    
                    {
                    cha--;
                    ene=ene+10;
                    setcolor(9);
                    setfillstyle(1,14);
                    rectangle(19,461,123,449);//Energy
                    rectangle(20,460,122,450);
                    bar(21,459,ene,451);
                    if(cha<1)
    
                        {
                        setcolor(4);
                        settextstyle(7,0,6);
                        outtextxy(140,100,"GAME OVER");
                        getch();
                        //***************************************************************************
                        wri.ad=as;
                        if (rea.ad>wri.ad)
                        ptr.write((signed char *)(&rea),sizeof(hs));
                        else
                        ptr.write((signed char *)(&wri),sizeof(hs));
                        ptr.close();
                        burn();
                        getch();
                        closegraph();
                        exit(1);
                    }
                }
                if(q>455&&q<470)
                if(w>x-50)
                if(w<x)
    
                    {
                    //cout<<"\a";
                    delay(20);
                    as=as+1;
                }
                n;
                bar(347,l-18,353,l);
                     //Bars
                b;
                bar(x-50,457,x,468);
                r(1,4);
                bar(x,457,x-20,465);
                bar(x-50,457,x-30,465);
                r(8,6);      //Car
                bar(x-40,459,x-10,463);
                r(8,14);
                bar(x-40,463,x-10,464);
                setcolor(0);
                circle(x-5,460,3);
                circle(x-5,460,2);   //Cylencer
                circle(x-5,460,1);
                r(1,8);
                bar(x-2,465,x-8,472);
                bar(x-48,465,x-42,472);
                setcolor(2);
                line(x-2,457,x-8,447); //Car tyre & roof
                line(x-50,457,x-42,447);
                line(x-42,447,x-8,447);
                putpixel(c,m,10);
                putpixel(c+1,m,10);
                putpixel(c+2,m,10);
                putpixel(c+3,m+1,10);
                putpixel(c+4,m+1,10);
                putpixel(c+5,m+1,10);
                putpixel(c+6,m,10);
                putpixel(c+7,m,10);
                putpixel(c+8,m,10);
                putpixel(c,m+1,9);
                putpixel(c+1,m+1,9);
                putpixel(c+2,m+1,9);
                putpixel(c+3,m+2,9);
                putpixel(c+4,m+2,9);
                putpixel(c+5,m+2,9);
                putpixel(c+6,m+1,9);
                putpixel(c+7,m+1,9);
                putpixel(c+8,m+1,9);
                setcolor(14);
                r(1,14);
                pieslice(100,50,300,50,18);
                pieslice(100,50,0,99,18);
                pieslice(100,50,-20,624,18);
                r(1,8);
                circle(t,p,8);
                setcolor(0);
                circle(t,p-sp,8);
                setcolor(4);    //Khadday
                circle(w,q,8);
                setcolor(0);
                circle(w,q-sp+2,8);
                if(l>480)
    
                    {
                    l=200;     //Return bars
                }
                if(p>488)
    
                    {
                    p=200;
                    t=random(100);
                    t=t+310;
                }
                if(q>650)
    
                    {
                    q=205;
                    w=random(100);
                    w=w+310;
                }
                if(m<-1)
    
                    {
                    m=random(150);
                    c=random(350);
                }
            }
    
                {
                a=getch();
                if(a=='K'|x>420)
    
                    {
                    setcolor(8);
                    line(300,190,200,500);
                    line(400,190,500,500);//Road
                    line(302,190,202,500);
                    line(402,190,502,500);
                    x=x-6;
                    o=o-6;
                    l=l+10;
                    m=m-1;
                    r(1,15);
                    bar(347,l,353,l+40);
                    n;//Bars
                    bar(347,l-18,353,l);
                    b;
                    bar(x,457,x-50,468);
                    r(1,4);
                    bar(x-30,457,x-50,465);
                    bar(x,457,x-20,465);
                    r(8,6);//Car
                    bar(x-40,459,x-10,463);
                    r(8,14);
                    bar(x-40,463,x-10,464);
                    setcolor(0);
                    circle(x-5,460,3);
                    circle(x-5,460,2); //Cylencer
                    circle(x-5,460,1);
                    putpixel(c,m,10);
                    putpixel(c+1,m,10);
                    putpixel(c+2,m,10);
                    putpixel(c+3,m+1,10);
                    putpixel(c+4,m+1,10);
                    putpixel(c+5,m+1,10);
                    putpixel(c+6,m,10);
                    putpixel(c+7,m,10);
                    putpixel(c+8,m,10);
                    putpixel(c,m+1,9);
                    putpixel(c+1,m+1,9);
                    putpixel(c+2,m+1,9);
                    putpixel(c+3,m+2,9);
                    putpixel(c+4,m+2,9);
                    putpixel(c+5,m+2,9);
                    putpixel(c+6,m+1,9);
                    putpixel(c+7,m+1,9);
                    putpixel(c+8,m+1,9);
                    r(1,8);
                    bar(x-2,465,x-8,472);
                    bar(x-48,465,x-42,472);
                    setcolor(2);
                    line(x-2,457,x-8,447); //Car tyre & roof
                    line(x-50,457,x-42,447);
                    line(x-42,447,x-8,447);
                    n;
                    bar(o+6,457,o,470);
                    bar(x+4,465,x-2,478);
                    bar(x-42,465,x-36,478);
                    setcolor(0); //No Car
                    line(x+4,457,x-2,447);
                    line(x-44,457,x-36,447);
                    line(x-8,447,x-2,447);
                }
                else if(a=='M'|x<320)
    
                    {
                    setcolor(8);
                    line(300,190,200,500);
                    line(400,190,500,500);
                    line(302,190,202,500);//Road
                    line(402,190,502,500);
                    x=x+6;
                    o=o+6;
                    l=l+10;
                    c=c+1;
                    r(1,15);
                    bar(347,l,353,l+40);
                    n;     //Bars
                    bar(347,l-18,353,l);
                    b;
                    bar(x-50,457,x,468);
                    r(1,4);
                    bar(x,457,x-20,465);
                    bar(x-50,457,x-30,465);
                    r(8,6);      //Car
                    bar(x-40,459,x-10,463);
                    r(8,14);
                    bar(x-40,463,x-10,464);
                    setcolor(0);
                    circle(x-5,460,3);
                    circle(x-5,460,2);   //Cylencer
                    circle(x-5,460,1);
                    putpixel(c,m,10);
                    putpixel(c+1,m,10);
                    putpixel(c+2,m,10);
                    putpixel(c+3,m+1,10);
                    putpixel(c+4,m+1,10);
                    putpixel(c+5,m+1,10);
                    putpixel(c+6,m,10);
                    putpixel(c+7,m,10);
                    putpixel(c+8,m,10);
                    putpixel(c-1,m,9);
                    putpixel(c+2,m+1,9);
                    putpixel(c+5,m,9);
                    setcolor(2);
                    line(x-2,457,x-8,447);
                    line(x-50,457,x-42,447);//Car Tyres
                    line(x-42,447,x-8,447);
                    r(1,8);
                    bar(x-2,465,x-8,472);
                    bar(x-50,465,x-42,472);
                    n;
                    bar(o-56,457,o-50,478);
                    bar(x-8,465,x-14,478);
                    bar(x-50,465,x-48,478);
                    setcolor(0);//No car
                    line(x-8,457,x-14,447);
                    line(x-56,457,x-48,447);
                    line(x-42,447,x-48,447);
                }
                if(l>480)
    
                    {
                    l=200;//Return bars
                }
                if(m<-1)
    
                    {
                    m=80;
                    c=315;
                }
            }
        }
        wri.ad=as;
        if (rea.ad>wri.ad)
        ptr.write((signed char *)(&rea),sizeof(hs));
        else
        ptr.write((signed char *)(&wri),sizeof(hs));
        ptr.close();
    }
    مشخصات نويسنده ي برنامه در متن برنامه آورده شده
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

  10. #18
    مدیر کـــــــل ســــایت
    رشته تحصیلی
    مهندسی کامپیوتر - نرم افزار
    اکانت شخصی
    ندارد
    نوشته ها
    7,883
    ارسال تشکر
    9,788
    دریافت تشکر: 29,042
    قدرت امتیاز دهی
    13974
    Array
    Admin's: جدید39

    پیش فرض

    خب دوستان از این به بعد سورس كد ها به همراه تصویری از برنامه و همچنین فایل اجرایی اون در انتهای برنامه فكر كنم كافی باشه.

    نكته: توجه داشته باشید كه برنامه ها رفته ، رفته گرافیكی تر و حرفه ای تر خواهد شد.

    نكته 2: توجه كنید كه Include های برنامه را باید با این سه کد زیر حتمآ از این به بعد جایگزین کنید تا برنامه ی شما در محیط برنامه نویسی Visual c اجرا شود.

    کد:
     #include "stdafx.h"
    #include <windows.h>
    #include <gl/gl.h>
    #include <gl/glu.h>
    #include <gl/glut.h>
    کد:
     // Block.c
    // OpenGL SuperBible, Chapter 1
    // Demonstrates an assortment of basic 3D concepts
    // Program by Richard S. Wright Jr.
    
    #include "../../Common/OpenGLSB.h"	// System and OpenGL Stuff
    #include "../../Common/GLTools.h"	// OpenGL toolkit
    #include <math.h>
    
    
    // Keep track of effects step
    int nStep = 0;
    
    
    // Lighting data
    GLfloat lightAmbient[] = { 0.2f, 0.2f, 0.2f, 1.0f };
    GLfloat lightDiffuse[] = { 0.7f, 0.7f, 0.7f, 1.0f };
    GLfloat lightSpecular[] = { 0.9f, 0.9f, 0.9f };
    GLfloat materialColor[] = { 0.8f, 0.0f, 0.0f };
    GLfloat lightpos[] = { -80.0f, 120.0f, 100.0f, 0.0f };
    GLfloat ground[3][3] = { { 0.0f, -25.0f, 0.0f },
                            { 10.0f, -25.0f, 0.0f },
                            { 10.0f, -25.0f, -10.0f } };
    
    GLuint textures[4];
    
    
    // Reduces a normal vector specified as a set of three coordinates,
    // to a unit normal vector of length one.
    void ReduceToUnit(float vector[3])
    	{
    	float length;
    	
    	// Calculate the length of the vector		
    	length = (float)sqrt((vector[0]*vector[0]) + 
    						(vector[1]*vector[1]) +
    						(vector[2]*vector[2]));
    
    	// Keep the program from blowing up by providing an exceptable
    	// value for vectors that may calculated too close to zero.
    	if(length == 0.0f)
    		length = 1.0f;
    
    	// Dividing each element by the length will result in a
    	// unit normal vector.
    	vector[0] /= length;
    	vector[1] /= length;
    	vector[2] /= length;
    	}
    
    
    // Points p1, p2, & p3 specified in counter clock-wise order
    void calcNormal(float v[3][3], float out[3])
    	{
    	float v1[3],v2[3];
    	static const int x = 0;
    	static const int y = 1;
    	static const int z = 2;
    
    	// Calculate two vectors from the three points
    	v1[x] = v[0][x] - v[1][x];
    	v1[y] = v[0][y] - v[1][y];
    	v1[z] = v[0][z] - v[1][z];
    
    	v2[x] = v[1][x] - v[2][x];
    	v2[y] = v[1][y] - v[2][y];
    	v2[z] = v[1][z] - v[2][z];
    
    	// Take the cross product of the two vectors to get
    	// the normal vector which will be stored in out
    	out[x] = v1[y]*v2[z] - v1[z]*v2[y];
    	out[y] = v1[z]*v2[x] - v1[x]*v2[z];
    	out[z] = v1[x]*v2[y] - v1[y]*v2[x];
    
    	// Normalize the vector (shorten length to one)
    	ReduceToUnit(out);
    	}
    
    
    // Creates a shadow projection matrix out of the plane equation
    // coefficients and the position of the light. The return value is stored
    // in destMat[][]
    void MakeShadowMatrix(GLfloat points[3][3], GLfloat lightPos[4], GLfloat destMat[4][4])
    	{
    	GLfloat planeCoeff[4];
    	GLfloat dot;
    
    	// Find the plane equation coefficients
    	// Find the first three coefficients the same way we
    	// find a normal.
    	calcNormal(points,planeCoeff);
    
    	// Find the last coefficient by back substitutions
    	planeCoeff[3] = - (
    		(planeCoeff[0]*points[2][0]) + (planeCoeff[1]*points[2][1]) +
    		(planeCoeff[2]*points[2][2]));
    
    
    	// Dot product of plane and light position
    	dot = planeCoeff[0] * lightPos[0] +
    			planeCoeff[1] * lightPos[1] +
    			planeCoeff[2] * lightPos[2] +
    			planeCoeff[3] * lightPos[3];
    
    	// Now do the projection
    	// First column
        destMat[0][0] = dot - lightPos[0] * planeCoeff[0];
        destMat[1][0] = 0.0f - lightPos[0] * planeCoeff[1];
        destMat[2][0] = 0.0f - lightPos[0] * planeCoeff[2];
        destMat[3][0] = 0.0f - lightPos[0] * planeCoeff[3];
    
    	// Second column
    	destMat[0][1] = 0.0f - lightPos[1] * planeCoeff[0];
    	destMat[1][1] = dot - lightPos[1] * planeCoeff[1];
    	destMat[2][1] = 0.0f - lightPos[1] * planeCoeff[2];
    	destMat[3][1] = 0.0f - lightPos[1] * planeCoeff[3];
    
    	// Third Column
    	destMat[0][2] = 0.0f - lightPos[2] * planeCoeff[0];
    	destMat[1][2] = 0.0f - lightPos[2] * planeCoeff[1];
    	destMat[2][2] = dot - lightPos[2] * planeCoeff[2];
    	destMat[3][2] = 0.0f - lightPos[2] * planeCoeff[3];
    
    	// Fourth Column
    	destMat[0][3] = 0.0f - lightPos[3] * planeCoeff[0];
    	destMat[1][3] = 0.0f - lightPos[3] * planeCoeff[1];
    	destMat[2][3] = 0.0f - lightPos[3] * planeCoeff[2];
    	destMat[3][3] = dot - lightPos[3] * planeCoeff[3];
    	}
    
    
    
    // Called to draw scene
    void RenderScene(void)
    	{
    	GLfloat cubeXform[4][4];
    
    	// Clear the window with current clearing color
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glShadeModel(GL_SMOOTH);
    	glEnable(GL_NORMALIZE);
    
    	glPushMatrix();
    
    
    	// Draw plane that the cube rests on
    	glDisable(GL_LIGHTING);
    	if(nStep == 5)
    		{
    		glColor3ub(255,255,255);
    		glEnable(GL_TEXTURE_2D);
    		glBindTexture(GL_TEXTURE_2D, textures[0]);
    		glBegin(GL_QUADS);
    			glTexCoord2f(0.0f, 0.0f);
    			glVertex3f(-100.0f, -25.3f, -100.0f);
    			glTexCoord2f(0.0f, 1.0f);
    			glVertex3f(-100.0f, -25.3f, 100.0f);		
    			glTexCoord2f(1.0f, 1.0f);
    			glVertex3f(100.0f,  -25.3f, 100.0f);
    			glTexCoord2f(1.0f, 0.0f);
    			glVertex3f(100.0f,  -25.3f, -100.0f);
    		glEnd();
    		}
    	else
    		{
    		glColor3f(0.0f, 0.0f, 0.90f); // Blue
    		glBegin(GL_QUADS);
    			glVertex3f(-100.0f, -25.3f, -100.0f);
    			glVertex3f(-100.0f, -25.3f, 100.0f);		
    			glVertex3f(100.0f,  -25.3f, 100.0f);
    			glVertex3f(100.0f,  -25.3f, -100.0f);
    		glEnd();
    		}
    
    
    	// Set drawing color to Red
    	glColor3f(1.0f, 0.0f, 0.0f);
    
    	// Enable, disable lighting
    	if(nStep > 2)
    		{
    		glEnable(GL_DEPTH_TEST);
    		glDepthFunc(GL_LEQUAL);
    		glEnable(GL_COLOR_MATERIAL);
    
    		glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
    		glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
    		glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular);
    		glEnable(GL_LIGHTING);
    		glEnable(GL_LIGHT0);
    		glMaterialfv(GL_FRONT, GL_SPECULAR,lightSpecular);
    		glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColor);
    		glMateriali(GL_FRONT, GL_SHININESS,128);
    		}
    
    	// Move the cube slightly forward and to the left
    	glTranslatef(-10.0f, 0.0f, 10.0f);
    
    	switch(nStep)
    		{
    		// Just draw the wire framed cube
    		case 0:
    			glutWireCube(50.0f);
    			break;
    
    		// Same wire cube with hidden line removal simulated
    		case 1:
    			// Front Face (before rotation)
    			glBegin(GL_LINES);
    				glVertex3f(25.0f,25.0f,25.0f);
    				glVertex3f(25.0f,-25.0f,25.0f);
    				
    				glVertex3f(25.0f,-25.0f,25.0f);
    				glVertex3f(-25.0f,-25.0f,25.0f);
    
    				glVertex3f(-25.0f,-25.0f,25.0f);
    				glVertex3f(-25.0f,25.0f,25.0f);
    
    				glVertex3f(-25.0f,25.0f,25.0f);
    				glVertex3f(25.0f,25.0f,25.0f);
    			glEnd();
    
    			// Top of cube
    			glBegin(GL_LINES);
    				// Front Face
    				glVertex3f(25.0f,25.0f,25.0f);
    				glVertex3f(25.0f,25.0f,-25.0f);
    				
    				glVertex3f(25.0f,25.0f,-25.0f);
    				glVertex3f(-25.0f,25.0f,-25.0f);
    
    				glVertex3f(-25.0f,25.0f,-25.0f);
    				glVertex3f(-25.0f,25.0f,25.0f);
    
    				glVertex3f(-25.0f,25.0f,25.0f);
    				glVertex3f(25.0f,25.0f,25.0f);
    			glEnd();
    
    			// Last two segments for effect
    			glBegin(GL_LINES);
    				glVertex3f(25.0f,25.0f,-25.0f);
    				glVertex3f(25.0f,-25.0f,-25.0f);
    
    				glVertex3f(25.0f,-25.0f,-25.0f);
    				glVertex3f(25.0f,-25.0f,25.0f);
    			glEnd();
    		
    			break;
    
    		// Uniform colored surface, looks 2D and goofey
    		case 2:
    			glutSolidCube(50.0f);
    			break;
    
    		case 3:
    			glutSolidCube(50.0f);
    			break;
    
    		// Draw a shadow with some lighting
    		case 4:
    			glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *) cubeXform);
    			glutSolidCube(50.0f);
    			glPopMatrix();
    
    			// Disable lighting, we'll just draw the shadow as black
    			glDisable(GL_LIGHTING);
    			
    			glPushMatrix();
    
    			MakeShadowMatrix(ground, lightpos, cubeXform);
    			glMultMatrixf((GLfloat *)cubeXform);
    			
    			glTranslatef(-10.0f, 0.0f, 10.0f);			
    			
    			// Set drawing color to Black
    			glColor3f(0.0f, 0.0f, 0.0f);
    
    			glutSolidCube(50.0f);
    			break;
    
    		case 5:
    			glColor3ub(255,255,255);
    			glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *) cubeXform);
    
    			// Front Face (before rotation)
    			glBindTexture(GL_TEXTURE_2D, textures[1]);
    			glBegin(GL_QUADS);
    				glTexCoord2f(1.0f, 1.0f);
    				glVertex3f(25.0f,25.0f,25.0f);
    				glTexCoord2f(1.0f, 0.0f);
    				glVertex3f(25.0f,-25.0f,25.0f);
    				glTexCoord2f(0.0f, 0.0f);
    				glVertex3f(-25.0f,-25.0f,25.0f);
    				glTexCoord2f(0.0f, 1.0f);
    				glVertex3f(-25.0f,25.0f,25.0f);
    			glEnd();
    
    			// Top of cube
    			glBindTexture(GL_TEXTURE_2D, textures[2]);
    			glBegin(GL_QUADS);
    				// Front Face
    				glTexCoord2f(0.0f, 0.0f);
    				glVertex3f(25.0f,25.0f,25.0f);
    				glTexCoord2f(1.0f, 0.0f);
    				glVertex3f(25.0f,25.0f,-25.0f);
    				glTexCoord2f(1.0f, 1.0f);
    				glVertex3f(-25.0f,25.0f,-25.0f);
    				glTexCoord2f(0.0f, 1.0f);
    				glVertex3f(-25.0f,25.0f,25.0f);
    			glEnd();
    
    			// Last two segments for effect
    			glBindTexture(GL_TEXTURE_2D, textures[3]);
    			glBegin(GL_QUADS);
    				glTexCoord2f(1.0f, 1.0f);
    				glVertex3f(25.0f,25.0f,-25.0f);
    				glTexCoord2f(1.0f, 0.0f);
    				glVertex3f(25.0f,-25.0f,-25.0f);
    				glTexCoord2f(0.0f, 0.0f);
    				glVertex3f(25.0f,-25.0f,25.0f);
    				glTexCoord2f(0.0f, 1.0f);
    				glVertex3f(25.0f,25.0f,25.0f);
    			glEnd();
    		
    
    			glPopMatrix();
    
    			// Disable lighting, we'll just draw the shadow as black
    			glDisable(GL_LIGHTING);
    			glDisable(GL_TEXTURE_2D);
    			
    			glPushMatrix();
    
    			MakeShadowMatrix(ground, lightpos, cubeXform);
    			glMultMatrixf((GLfloat *)cubeXform);
    			
    			glTranslatef(-10.0f, 0.0f, 10.0f);			
    			
    			// Set drawing color to Black
    			glColor3f(0.0f, 0.0f, 0.0f);
    			glutSolidCube(50.0f);
    			break;
    			
    		}
    
    	glPopMatrix();
    
    	// Flush drawing commands
    	glutSwapBuffers();
    	}
    
    // This function does any needed initialization on the rendering
    // context. 
    void SetupRC()
    	{
            GLbyte *pBytes;
            GLint nWidth, nHeight, nComponents;
            GLenum format;
    
    	// Black background
    	glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
    
            glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_MODULATE);
            glGenTextures(4, textures);
            
    	// Load the texture objects
            pBytes = gltLoadTGA("floor.tga", &nWidth, &nHeight, &nComponents, &format);
            glBindTexture(GL_TEXTURE_2D, textures[0]);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    	glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0,
    		format, GL_UNSIGNED_BYTE, pBytes);
    	free(pBytes);
    
    	pBytes = gltLoadTGA("Block4.tga", &nWidth, &nHeight, &nComponents, &format);
            glBindTexture(GL_TEXTURE_2D, textures[1]);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    	glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0,
    		format, GL_UNSIGNED_BYTE, pBytes);
    	free(pBytes);
    
    	pBytes = gltLoadTGA("block5.tga", &nWidth, &nHeight, &nComponents, &format);
            glBindTexture(GL_TEXTURE_2D, textures[2]);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    	glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0,
    		format, GL_UNSIGNED_BYTE, pBytes);
    	free(pBytes);
    
    	pBytes = gltLoadTGA("block6.tga", &nWidth, &nHeight, &nComponents, &format);
            glBindTexture(GL_TEXTURE_2D, textures[3]);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    	glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0,
    		format, GL_UNSIGNED_BYTE, pBytes);
    	free(pBytes);
            }
    
    void KeyPressFunc(unsigned char key, int x, int y)
    	{
    	if(key == 32)
    		{
    		nStep++;
    
    		if(nStep > 5)
    			nStep = 0;
    		}
    
    	// Refresh the Window
    	glutPostRedisplay();
    	}
    
    
    void ChangeSize(int w, int h)
    	{
    	// Calculate new clipping volume
    	GLfloat windowWidth;
    	GLfloat windowHeight;
    
    	// Prevent a divide by zero, when window is too short
    	// (you cant make a window of zero width).
    	if(h == 0)
    		h = 1;
    
    	// Keep the square square
    	if (w <= h) 
    		{
    		windowHeight = 100.0f*(GLfloat)h/(GLfloat)w;
    		windowWidth = 100.0f;
    		}
        else 
    		{
    		windowWidth = 100.0f*(GLfloat)w/(GLfloat)h;
    		windowHeight = 100.0f;
    		}
    
            // Set the viewport to be the entire window
            glViewport(0, 0, w, h);
    
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
    
    	// Set the clipping volume
    	glOrtho(-100.0f, windowWidth, -100.0f, windowHeight, -200.0f, 200.0f);
    
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();
    
    	glLightfv(GL_LIGHT0,GL_POSITION, lightpos);
    
    	glRotatef(30.0f, 1.0f, 0.0f, 0.0f);
    	glRotatef(330.0f, 0.0f, 1.0f, 0.0f);
    	}
    
    int main(int argc, char* argv[])
    	{
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    	glutCreateWindow("3D Effects Demo");
    	glutReshapeFunc(ChangeSize);
    	glutKeyboardFunc(KeyPressFunc);
    	glutDisplayFunc(RenderScene);
    
    	SetupRC();
    
    	glutMainLoop();
    	glDeleteTextures(4,textures);
    	return 0;
    	}
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

  11. #19
    مدیر کـــــــل ســــایت
    رشته تحصیلی
    مهندسی کامپیوتر - نرم افزار
    اکانت شخصی
    ندارد
    نوشته ها
    7,883
    ارسال تشکر
    9,788
    دریافت تشکر: 29,042
    قدرت امتیاز دهی
    13974
    Array
    Admin's: جدید39

    پیش فرض

    برنامه Bounce

    کد:
    // Bounce.c
    // Demonstrates a simple animated rectangle program with GLUT
    // OpenGL SuperBible, 3rd Edition
    // Richard S. Wright Jr.
    // rwright@starstonesoftware.com
    
    #include "../../Common/OpenGLSB.h"	// System and OpenGL Stuff
    
    
    
    // Initial square position and size
    GLfloat x = 0.0f;
    GLfloat y = 0.0f;
    GLfloat rsize = 25;
    
    // Step size in x and y directions
    // (number of pixels to move each time)
    GLfloat xstep = 1.0f;
    GLfloat ystep = 1.0f;
    
    // Keep track of windows changing width and height
    GLfloat windowWidth;
    GLfloat windowHeight;
    
    ///////////////////////////////////////////////////////////
    // Called to draw scene
    void RenderScene(void)
    	{
    	// Clear the window with current clearing color
    	glClear(GL_COLOR_BUFFER_BIT);
    
       	// Set current drawing color to red
    	//		   R	 G	   B
    	glColor3f(1.0f, 0.0f, 0.0f);
    
    	// Draw a filled rectangle with current color
    	glRectf(x, y, x + rsize, y - rsize);
    
        // Flush drawing commands and swap
        glutSwapBuffers();
    	}
    
    ///////////////////////////////////////////////////////////
    // Called by GLUT library when idle (window not being
    // resized or moved)
    void TimerFunction(int value)
        {
        // Reverse direction when you reach left or right edge
        if(x > windowWidth-rsize || x < -windowWidth)
            xstep = -xstep;
    
        // Reverse direction when you reach top or bottom edge
        if(y > windowHeight || y < -windowHeight + rsize)
            ystep = -ystep;
    
    	// Actually move the square
        x += xstep;
        y += ystep;
    
        // Check bounds. This is in case the window is made
        // smaller while the rectangle is bouncing and the 
    	// rectangle suddenly finds itself outside the new
        // clipping volume
        if(x > (windowWidth-rsize + xstep))
            x = windowWidth-rsize-1;
    	else if(x < -(windowWidth + xstep))
    		x = -windowWidth -1;
    
        if(y > (windowHeight + ystep))
            y = windowHeight-1; 
    	else if(y < -(windowHeight - rsize + ystep))
    		y = -windowHeight + rsize - 1;
    
    
    
         // Redraw the scene with new coordinates
        glutPostRedisplay();
        glutTimerFunc(33,TimerFunction, 1);
        }
    
    
    ///////////////////////////////////////////////////////////
    // Setup the rendering state
    void SetupRC(void)
        {
        // Set clear color to blue
        glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
        }
    
    
    ///////////////////////////////////////////////////////////
    // Called by GLUT library when the window has chanaged size
    void ChangeSize(int w, int h)
        {
        GLfloat aspectRatio;
    
        // Prevent a divide by zero
        if(h == 0)
            h = 1;
    		
        // Set Viewport to window dimensions
        glViewport(0, 0, w, h);
    
        // Reset coordinate system
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
    
        // Establish clipping volume (left, right, bottom, top, near, far)
        aspectRatio = (GLfloat)w / (GLfloat)h;
        if (w <= h) 
            {
            windowWidth = 100;
            windowHeight = 100 / aspectRatio;
            glOrtho (-100.0, 100.0, -windowHeight, windowHeight, 1.0, -1.0);
            }
        else 
            {
            windowWidth = 100 * aspectRatio;
            windowHeight = 100;
            glOrtho (-windowWidth, windowWidth, -100.0, 100.0, 1.0, -1.0);
            }
    
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        }
    
    ///////////////////////////////////////////////////////////
    // Main program entry point
    int main(int argc, char* argv[])
    	{
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    	glutInitWindowSize(800,600);
            glutCreateWindow("Bounce");
    	glutDisplayFunc(RenderScene);
            glutReshapeFunc(ChangeSize);
    	glutTimerFunc(33, TimerFunction, 1);
    
    	SetupRC();
    
    	glutMainLoop();
            
            return 0;
        }
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

  12. #20
    مدیر کـــــــل ســــایت
    رشته تحصیلی
    مهندسی کامپیوتر - نرم افزار
    اکانت شخصی
    ندارد
    نوشته ها
    7,883
    ارسال تشکر
    9,788
    دریافت تشکر: 29,042
    قدرت امتیاز دهی
    13974
    Array
    Admin's: جدید39

    پیش فرض

    برنامه ای كه از خط ساخته شده و با كیبور می چرخد.

    کد:
    // Lines.c
    // Demonstrates primative GL_LINES
    // OpenGL SuperBible, 3rd Edition
    // Richard S. Wright Jr.
    // rwright@starstonesoftware.com
    
    #include "../../Common/OpenGLSB.h"	// System and OpenGL Stuff
    
    
    // Define a constant for the value of PI
    #define GL_PI 3.1415f
    
    // Rotation amounts
    static GLfloat xRot = 0.0f;
    static GLfloat yRot = 0.0f;
    
    ///////////////////////////////////////////////////////////
    // Called to draw scene
    void RenderScene(void)
    	{
            GLfloat x,y,z,angle; // Storeage for coordinates and angles
    
    	// Clear the window with current clearing color
    	glClear(GL_COLOR_BUFFER_BIT);
    
    	// Save matrix state and do the rotation
    	glPushMatrix();
    	glRotatef(xRot, 1.0f, 0.0f, 0.0f);
    	glRotatef(yRot, 0.0f, 1.0f, 0.0f);
    
    	// Call only once for all remaining points
    	glBegin(GL_LINES);
    
    	z = 0.0f;
    	for(angle = 0.0f; angle <= GL_PI; angle += (GL_PI / 20.0f))
    		{
    		// Top half of the circle
    		x = 50.0f*sin(angle);
    		y = 50.0f*cos(angle);
    		glVertex3f(x, y, z);
    
    		// Bottom half of the circle
    		x = 50.0f*sin(angle+GL_PI);
    		y = 50.0f*cos(angle+GL_PI);
    		glVertex3f(x, y, z);	
    		}
    
    	// Done drawing points
    	glEnd();
    
    	// Restore transformations
    	glPopMatrix();
    
    	// Flush drawing commands
    	glutSwapBuffers();
    	}
    
    ///////////////////////////////////////////////////////////
    // This function does any needed initialization on the 
    // rendering context. 
    void SetupRC()
    	{
    	// Black background
    	glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
    
    	// Set drawing color to green
    	glColor3f(0.0f, 1.0f, 0.0f);
    	}
    
    ///////////////////////////////////////////////////////////
    // Respond to arrow keys
    void SpecialKeys(int key, int x, int y)
    	{
    	if(key == GLUT_KEY_UP)
    		xRot-= 5.0f;
    
    	if(key == GLUT_KEY_DOWN)
    		xRot += 5.0f;
    
    	if(key == GLUT_KEY_LEFT)
    		yRot -= 5.0f;
    
    	if(key == GLUT_KEY_RIGHT)
    		yRot += 5.0f;
    
    	if(key > 356.0f)
    		xRot = 0.0f;
    
    	if(key < -1.0f)
    		xRot = 355.0f;
    
    	if(key > 356.0f)
    		yRot = 0.0f;
    
    	if(key < -1.0f)
    		yRot = 355.0f;
    
    	// Refresh the Window
    	glutPostRedisplay();
    	}
    
    ///////////////////////////////////////////////////////////
    // Window has changed size, recalculate projection
    void ChangeSize(int w, int h)
    	{
    	GLfloat nRange = 100.0f;
    
    	// Prevent a divide by zero
    	if(h == 0)
    		h = 1;
    
    	// Set Viewport to window dimensions
        glViewport(0, 0, w, h);
    
    	// Reset coordinate system
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    
    	// Establish clipping volume (left, right, bottom, top, near, far)
        if (w <= h) 
    		glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
        else 
    		glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);
    
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    	}
    
    ///////////////////////////////////////////////////////////
    // Main Program Entry Point
    int main(int argc, char* argv[])
    	{
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    	glutInitWindowSize(800,600);
    	glutCreateWindow("Lines Example");
    	glutReshapeFunc(ChangeSize);
    	glutSpecialFunc(SpecialKeys);
    	glutDisplayFunc(RenderScene);
    	SetupRC();
    	glutMainLoop();
    
    	return 0;
    	}
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

  13. کاربرانی که از پست مفید Admin سپاس کرده اند.


صفحه 2 از 14 نخستنخست 123456789101112 ... آخرینآخرین

اطلاعات موضوع

کاربرانی که در حال مشاهده این موضوع هستند

در حال حاضر 1 کاربر در حال مشاهده این موضوع است. (0 کاربران و 1 مهمان ها)

موضوعات مشابه

  1. مقاله: سیستم عامل ( مقاله )
    توسط Admin در انجمن بخش مقالات نرم افزار
    پاسخ ها: 9
    آخرين نوشته: 25th April 2013, 01:33 AM
  2. پاسخ ها: 9
    آخرين نوشته: 23rd November 2008, 05:47 PM
  3. آنتی ویروس و خطرات ویروسها ( مقاله )
    توسط Admin در انجمن بخش مقالات نرم افزار
    پاسخ ها: 8
    آخرين نوشته: 9th September 2008, 06:47 PM
  4. پاسخ ها: 0
    آخرين نوشته: 7th September 2008, 02:43 PM
  5. آموزش نصب بازی روی گوشی های سری d سامسونگ
    توسط SOURCE MOBILE در انجمن آموزش
    پاسخ ها: 0
    آخرين نوشته: 7th September 2008, 04:56 AM

کلمات کلیدی این موضوع

مجوز های ارسال و ویرایش

  • شما نمیتوانید موضوع جدیدی ارسال کنید
  • شما امکان ارسال پاسخ را ندارید
  • شما نمیتوانید فایل پیوست کنید.
  • شما نمیتوانید پست های خود را ویرایش کنید
  •