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

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

توجه داشته باشید، در صورتی که عضو سایت نباشید نمی توانید از تمامی امکانات و خدمات سایت استفاده کنید.
نمایش نتایج: از شماره 1 تا 10 , از مجموع 137

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

Hybrid View

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

    پیش فرض پاسخ : برنامه هایی گرافیكی ( OpenGL )

    برنامه ستاره که با کیبور هم حرکت می کند.

    کد:
    // Star.c
    // OpenGL SuperBible, Chapter 4
    // Demonstrates OpenGL Primative GL_POINTS with point size
    // Program by Richard S. Wright Jr.
    
    #include "../../Common/OpenGLSB.h"	// System and OpenGL Stuff
    #include <math.h>
    
    
    // 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;
    
    // Flags for effects
    #define MODE_SOLID 0
    #define MODE_LINE  1
    #define MODE_POINT 2
    
    int iMode = MODE_SOLID;
    GLboolean bEdgeFlag = TRUE;
    
    ///////////////////////////////////////////////////////////////////////////////
    // Reset flags as appropriate in response to menu selections
    void ProcessMenu(int value)
    	{
    	switch(value)
    		{
    		case 1:
    			iMode = MODE_SOLID;
    			break;
    
    		case 2:
    			iMode = MODE_LINE;
    			break;
    
    		case 3:
    			iMode = MODE_POINT;
    			break;
    
    		case 4:
    			bEdgeFlag = TRUE;
    			break;
    
    		case 5:
    		default:
    			bEdgeFlag = FALSE;
    			break;
    		}
    
    	glutPostRedisplay();
    	}
    
    
    // Called to draw scene
    void RenderScene(void)
    	{
    	// Clear the window
    	glClear(GL_COLOR_BUFFER_BIT);
    
    
    	// Draw back side as a polygon only, if flag is set
    	if(iMode == MODE_LINE)
    		glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    
    	if(iMode == MODE_POINT)
    		glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
    
    	if(iMode == MODE_SOLID)
    		glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    
    
    	// Save matrix state and do the rotation
    	glPushMatrix();
    	glRotatef(xRot, 1.0f, 0.0f, 0.0f);
    	glRotatef(yRot, 0.0f, 1.0f, 0.0f);
    
    
    	// Begin the triangles
    	glBegin(GL_TRIANGLES);
    
    		glEdgeFlag(bEdgeFlag);
    		glVertex2f(-20.0f, 0.0f);
    		glEdgeFlag(TRUE);
    		glVertex2f(20.0f, 0.0f);
    		glVertex2f(0.0f, 40.0f);
    
    		glVertex2f(-20.0f,0.0f);
    		glVertex2f(-60.0f,-20.0f);
    		glEdgeFlag(bEdgeFlag);
    		glVertex2f(-20.0f,-40.0f);
    		glEdgeFlag(TRUE);
    
    		glVertex2f(-20.0f,-40.0f);
    		glVertex2f(0.0f, -80.0f);
    		glEdgeFlag(bEdgeFlag);
    		glVertex2f(20.0f, -40.0f);		
    		glEdgeFlag(TRUE);
    
    		glVertex2f(20.0f, -40.0f);		
    		glVertex2f(60.0f, -20.0f);
    		glEdgeFlag(bEdgeFlag);
    		glVertex2f(20.0f, 0.0f);
    		glEdgeFlag(TRUE);
    
    		// Center square as two triangles
    		glEdgeFlag(bEdgeFlag);
    		glVertex2f(-20.0f, 0.0f);
    		glVertex2f(-20.0f,-40.0f);
    		glVertex2f(20.0f, 0.0f);
    		
    		glVertex2f(-20.0f,-40.0f);
    		glVertex2f(20.0f, -40.0f);
    		glVertex2f(20.0f, 0.0f);
    		glEdgeFlag(TRUE);
    	
    	// Done drawing Triangles
    	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);
    	}
    
    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 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 projection matrix stack
    	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);
    
    	// Reset Model view matrix stack
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    	}
    
    int main(int argc, char* argv[])
    	{
    	int nModeMenu;
    	int nEdgeMenu;
    	int nMainMenu;
    
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    	glutCreateWindow("Solid and Outlined Star");
    	
    	// Create the Menu
    	nModeMenu = glutCreateMenu(ProcessMenu);
    	glutAddMenuEntry("Solid",1);
    	glutAddMenuEntry("Outline",2);
    	glutAddMenuEntry("Points",3);
    
    	nEdgeMenu = glutCreateMenu(ProcessMenu);
    	glutAddMenuEntry("On",4);
    	glutAddMenuEntry("Off",5);
    
    	nMainMenu = glutCreateMenu(ProcessMenu);
    	glutAddSubMenu("Mode", nModeMenu);
    	glutAddSubMenu("Edges", nEdgeMenu);
    	glutAttachMenu(GLUT_RIGHT_BUTTON);
    	
    	glutReshapeFunc(ChangeSize);
    	glutSpecialFunc(SpecialKeys);
    	glutDisplayFunc(RenderScene);
    	SetupRC();
    	glutMainLoop();
    
    	return 0;
    	}
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

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

    پیش فرض پاسخ : برنامه هایی گرافیكی ( OpenGL )

    برنامه ای كه مركب از دو برنامه Bounce ( پست 19 ) و برنامه ی پست 27 است.

    کد:
    // Stencil.c
    // 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)
        {
        GLdouble dRadius = 0.1; // Initial radius of spiral
        GLdouble dAngle;        // Looping variable
                
        // Clear blue window
        glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
            
        // Use 0 for clear stencil, enable stencil test
        glClearStencil(0.0f);
        glEnable(GL_STENCIL_TEST);
    
        // Clear color and stencil buffer
        glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
                    
        // All drawing commands fail the stencil test, and are not
        // drawn, but increment the value in the stencil buffer. 
        glStencilFunc(GL_NEVER, 0x0, 0x0);
        glStencilOp(GL_INCR, GL_INCR, GL_INCR);
    
        // Spiral pattern will create stencil pattern
        // Draw the spiral pattern with white lines. We 
        // make the lines  white to demonstrate that the 
        // stencil function prevents them from being drawn
        glColor3f(1.0f, 1.0f, 1.0f);
        glBegin(GL_LINE_STRIP);
            for(dAngle = 0; dAngle < 400.0; dAngle += 0.1)
                {
                glVertex2d(dRadius * cos(dAngle), dRadius * sin(dAngle));
                dRadius *= 1.002;
                }
        glEnd();
                
        // Now, allow drawing, except where the stencil pattern is 0x1
        // and do not make any further changes to the stencil buffer
        glStencilFunc(GL_NOTEQUAL, 0x1, 0x1);
        glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
            
        // Now draw red bouncing square
        // (x and y) are modified by a timer function
        glColor3f(1.0f, 0.0f, 0.0f);
        glRectf(x, y, x + rsize, y - rsize);
        
        // All done, do the buffer 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;
    
    
        // 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)
            x = windowWidth-rsize-1;
    
        if(y > windowHeight)
            y = windowHeight-1; 
    
        // Actually move the square
        x += xstep;
        y += ystep;
    
         // Redraw the scene with new coordinates
        glutPostRedisplay();
        glutTimerFunc(33,TimerFunction, 1);
        }
    
    
    ///////////////////////////////////////////////////////////
    // 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();
        }
        
        
    ///////////////////////////////////////////////////////////
    // Program entry point
    int main(int argc, char* argv[])
        {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_STENCIL);
        glutInitWindowSize(800,600);
        glutCreateWindow("OpenGL Stencil Test");
        glutReshapeFunc(ChangeSize);
        glutDisplayFunc(RenderScene);
            glutTimerFunc(33, TimerFunction, 1);
        glutMainLoop();
    
        return 0;
        }
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

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

    پیش فرض پاسخ : برنامه هایی گرافیكی ( OpenGL )

    کد:
    // Triangle.c
    // OpenGL SuperBible, Chapter 4
    // Demonstrates OpenGL Triangle Fans, backface culling, and depth testing
    // Program by Richard S. Wright Jr.
    #include "../../Common/OpenGLSB.h"	// System and OpenGL Stuff
    #include <math.h>
    
    
    // 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;
    
    // Flags for effects
    // Flags for effects
    int iCull = 0;
    int iOutline = 0;
    int iDepth = 0;
    
    ///////////////////////////////////////////////////////////////////////////////
    // Reset flags as appropriate in response to menu selections
    void ProcessMenu(int value)
    	{
    	switch(value)
    		{
    		case 1:
    			iDepth = !iDepth;
    			break;
    
    		case 2:
    			iCull = !iCull;
    			break;
    
    		case 3:
    			iOutline = !iOutline;
    		default:
    			break;
    		}
    
    	glutPostRedisplay();
    	}
    
    
    // Called to draw scene
    void RenderScene(void)
    	{
    	GLfloat x,y,angle;  // Storage for coordinates and angles
    	int iPivot = 1;		// Used to flag alternating colors
    
    	// Clear the window and the depth buffer
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    	// Turn culling on if flag is set
    	if(iCull)
    		glEnable(GL_CULL_FACE);
    	else
    		glDisable(GL_CULL_FACE);
    
    	// Enable depth testing if flag is set
    	if(iDepth)
    		glEnable(GL_DEPTH_TEST);
    	else
    		glDisable(GL_DEPTH_TEST);
    
    	// Draw back side as a polygon only, if flag is set
    	if(iOutline)
    		glPolygonMode(GL_BACK,GL_LINE);
    	else
    		glPolygonMode(GL_BACK,GL_FILL);
    		
    
    	// Save matrix state and do the rotation
    	glPushMatrix();
    	glRotatef(xRot, 1.0f, 0.0f, 0.0f);
    	glRotatef(yRot, 0.0f, 1.0f, 0.0f);
    
    
    	// Begin a triangle fan
    	glBegin(GL_TRIANGLE_FAN);
    
    	// Pinnacle of cone is shared vertex for fan, moved up Z axis
    	// to produce a cone instead of a circle
    	glVertex3f(0.0f, 0.0f, 75.0f);
    	
    	// Loop around in a circle and specify even points along the circle
    	// as the vertices of the triangle fan
    	for(angle = 0.0f; angle < (2.0f*GL_PI); angle += (GL_PI/8.0f))
    		{
    		// Calculate x and y position of the next vertex
    		x = 50.0f*sin(angle);
    		y = 50.0f*cos(angle);
    	
    		// Alternate color between red and green
    		if((iPivot %2) == 0)
    			glColor3f(0.0f, 1.0f, 0.0f);
    		else
    			glColor3f(1.0f, 0.0f, 0.0f);
    			
    		// Increment pivot to change color next time
    		iPivot++;
    
    		// Specify the next vertex for the triangle fan
    		glVertex2f(x, y);
    		}
    
    	// Done drawing fan for cone
    	glEnd();
    
    
    	// Begin a new triangle fan to cover the bottom
    	glBegin(GL_TRIANGLE_FAN);
    
    	// Center of fan is at the origin
    	glVertex2f(0.0f, 0.0f);
    	for(angle = 0.0f; angle < (2.0f*GL_PI); angle += (GL_PI/8.0f))
    		{
    		// Calculate x and y position of the next vertex
    		x = 50.0f*sin(angle);
    		y = 50.0f*cos(angle);
    	
    		// Alternate color between red and green
    		if((iPivot %2) == 0)
    			glColor3f(0.0f, 1.0f, 0.0f);
    		else
    			glColor3f(1.0f, 0.0f, 0.0f);
    			
    		// Increment pivot to change color next time
    		iPivot++;
    
    		// Specify the next vertex for the triangle fan
    		glVertex2f(x, y);
    		}
    
    	// Done drawing the fan that covers the bottom
    	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);
    
    	// Set color shading model to flat
    	glShadeModel(GL_FLAT);
    
    	// Clock wise wound polygons are front facing, this is reversed
    	// because we are using triangle fans
    	glFrontFace(GL_CW);
    	}
    
    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 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 projection matrix stack
    	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);
    
    	// Reset Model view matrix stack
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    	}
    
    int main(int argc, char* argv[])
    	{
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    	glutCreateWindow("Triangle Culling Example");
    	
    	// Create the Menu
    	glutCreateMenu(ProcessMenu);
    	glutAddMenuEntry("Toggle depth test",1);
    	glutAddMenuEntry("Toggle cull backface",2);
    	glutAddMenuEntry("Toggle outline back",3);
    	glutAttachMenu(GLUT_RIGHT_BUTTON);
    	
    	glutReshapeFunc(ChangeSize);
    	glutSpecialFunc(SpecialKeys);
    	glutDisplayFunc(RenderScene);
    	SetupRC();
    	glutMainLoop();
    
    	return 0;
    	}
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

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

    پیش فرض پاسخ : برنامه هایی گرافیكی ( OpenGL )

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

    کد:
    // Atom.c
    // OpenGL SuperBible
    // Demonstrates OpenGL coordinate transformation
    // Program by Richard S. Wright Jr.
    #include "../../Common/OpenGLSB.h"	// System and OpenGL Stuff#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 GLfloat 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);	
    
    	// Red Nucleus
    	glColor3ub(255, 0, 0);
    	glutSolidSphere(10.0f, 15, 15);
    
    	// Yellow Electrons
    	glColor3ub(255,255,0);
    
    	// First Electron Orbit
    	// Save viewing transformation
    	glPushMatrix();
    
    	// Rotate by angle of revolution
    	glRotatef(fElect1, 0.0f, 1.0f, 0.0f);
    
    	// Translate out from origin to orbit distance
    	glTranslatef(90.0f, 0.0f, 0.0f);
    
    	// Draw the electron
    	glutSolidSphere(6.0f, 15, 15);
        
    
    	// Restore the viewing transformation
    	glPopMatrix();
    
    	// Second Electron Orbit
    	glPushMatrix();
    	glRotatef(45.0f, 0.0f, 0.0f, 1.0f);
    	glRotatef(fElect1, 0.0f, 1.0f, 0.0f);
    	glTranslatef(-70.0f, 0.0f, 0.0f);
    	glutSolidSphere(6.0f, 15, 15);
    	glPopMatrix();
    
    
    	// Third Electron Orbit
    	glPushMatrix();
    	glRotatef(360.0f-45.0f,0.0f, 0.0f, 1.0f);
    	glRotatef(fElect1, 0.0f, 1.0f, 0.0f);
    	glTranslatef(0.0f, 0.0f, 60.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);
            glutInitWindowSize(800, 600);
    	glutCreateWindow("OpenGL Atom");
    	glutReshapeFunc(ChangeSize);
    	glutSpecialFunc(SpecialKeys);
    	glutDisplayFunc(RenderScene);
            glutTimerFunc(500, TimerFunc, 1);
    	SetupRC();
    	glutMainLoop();
    
    	return 0;
    	}
    این برنامه به صورت انیمیشن می باشد.
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

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

    پیش فرض پاسخ : برنامه هایی گرافیكی ( OpenGL )

    برنامه ی برای محیط دو بعدی ( Ortho )

    کد:
    // Ortho.c
    // OpenGL SuperBible
    // Richard S. Wright Jr.
    // Demonstrates Orthographic Projection
    
    #include "../../Common/OpenGLSB.h"	// System and OpenGL Stuff
    
    // Rotation amounts
    static GLfloat xRot = 0.0f;
    static GLfloat yRot = 0.0f;
    
    
    // Change viewing volume and viewport.  Called when window is resized
    void ChangeSize(GLsizei w, GLsizei h)
        {
        GLfloat nRange = 120.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();
        }
    
    
    
    // This function does any needed initialization on the rendering
    // context.  Here it sets up and initializes the lighting for
    // the scene.
    void SetupRC()
        {
        // Light values and coordinates
        GLfloat  whiteLight[] = { 0.45f, 0.45f, 0.45f, 1.0f };
        GLfloat  sourceLight[] = { 0.25f, 0.25f, 0.25f, 1.0f };
        GLfloat	 lightPos[] = { -50.f, 25.0f, 250.0f, 0.0f };
    
        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
    
        // Enable lighting
        glEnable(GL_LIGHTING);
    
        // Setup and enable light 0
        glLightModelfv(GL_LIGHT_MODEL_AMBIENT,whiteLight);
        glLightfv(GL_LIGHT0,GL_AMBIENT,sourceLight);
        glLightfv(GL_LIGHT0,GL_DIFFUSE,sourceLight);
        glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
        glEnable(GL_LIGHT0);
    
        // Enable color tracking
        glEnable(GL_COLOR_MATERIAL);
    	
        // Set Material properties to follow glColor values
        glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
    
        // Black blue background
        glClearColor(0.0f, 0.0f, 0.0f, 1.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;
                    
            xRot = (GLfloat)((const int)xRot % 360);
            yRot = (GLfloat)((const int)yRot % 360);
    
    	// Refresh the Window
    	glutPostRedisplay();
    	}
    
    
    // Called to draw scene
    void RenderScene(void)
        {
        float fZ,bZ;
    
        // Clear the window with current clearing color
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        fZ = 100.0f;
        bZ = -100.0f;
    
        // Save the matrix state and do the rotations
        glPushMatrix();
        glRotatef(xRot, 1.0f, 0.0f, 0.0f);
        glRotatef(yRot, 0.0f, 1.0f, 0.0f);
    
        // Set material color, Red
        glColor3f(1.0f, 0.0f, 0.0f);
    
        // Front Face ///////////////////////////////////
        glBegin(GL_QUADS);
            // Pointing straight out Z
            glNormal3f(0.0f, 0.0f, 1.0f);	
    
            // Left Panel
            glVertex3f(-50.0f, 50.0f, fZ);
            glVertex3f(-50.0f, -50.0f, fZ);
            glVertex3f(-35.0f, -50.0f, fZ);
            glVertex3f(-35.0f,50.0f,fZ);
    
            // Right Panel
            glVertex3f(50.0f, 50.0f, fZ);
            glVertex3f(35.0f, 50.0f, fZ);
            glVertex3f(35.0f, -50.0f, fZ);
            glVertex3f(50.0f,-50.0f,fZ);
    
            // Top Panel
            glVertex3f(-35.0f, 50.0f, fZ);
            glVertex3f(-35.0f, 35.0f, fZ);
            glVertex3f(35.0f, 35.0f, fZ);
            glVertex3f(35.0f, 50.0f,fZ);
    
            // Bottom Panel
            glVertex3f(-35.0f, -35.0f, fZ);
            glVertex3f(-35.0f, -50.0f, fZ);
            glVertex3f(35.0f, -50.0f, fZ);
            glVertex3f(35.0f, -35.0f,fZ);
    
            // Top length section ////////////////////////////
            // Normal points up Y axis
            glNormal3f(0.0f, 1.0f, 0.0f);
            glVertex3f(-50.0f, 50.0f, fZ);
            glVertex3f(50.0f, 50.0f, fZ);
            glVertex3f(50.0f, 50.0f, bZ);
            glVertex3f(-50.0f,50.0f,bZ);
    		
            // Bottom section
            glNormal3f(0.0f, -1.0f, 0.0f);
            glVertex3f(-50.0f, -50.0f, fZ);
            glVertex3f(-50.0f, -50.0f, bZ);
            glVertex3f(50.0f, -50.0f, bZ);
            glVertex3f(50.0f, -50.0f, fZ);
    
            // Left section
            glNormal3f(1.0f, 0.0f, 0.0f);
            glVertex3f(50.0f, 50.0f, fZ);
            glVertex3f(50.0f, -50.0f, fZ);
            glVertex3f(50.0f, -50.0f, bZ);
            glVertex3f(50.0f, 50.0f, bZ);
    
            // Right Section
            glNormal3f(-1.0f, 0.0f, 0.0f);
            glVertex3f(-50.0f, 50.0f, fZ);
            glVertex3f(-50.0f, 50.0f, bZ);
            glVertex3f(-50.0f, -50.0f, bZ);
            glVertex3f(-50.0f, -50.0f, fZ);
        glEnd();
    
        glFrontFace(GL_CW);		// clock-wise polygons face out
    
        glBegin(GL_QUADS);
            // Back section
            // Pointing straight out Z
            glNormal3f(0.0f, 0.0f, -1.0f);	
    
            // Left Panel
            glVertex3f(-50.0f, 50.0f, bZ);
            glVertex3f(-50.0f, -50.0f, bZ);
            glVertex3f(-35.0f, -50.0f, bZ);
            glVertex3f(-35.0f,50.0f,bZ);
    
            // Right Panel
            glVertex3f(50.0f, 50.0f, bZ);
            glVertex3f(35.0f, 50.0f, bZ);
            glVertex3f(35.0f, -50.0f, bZ);
            glVertex3f(50.0f,-50.0f,bZ);
    
            // Top Panel
            glVertex3f(-35.0f, 50.0f, bZ);
            glVertex3f(-35.0f, 35.0f, bZ);
            glVertex3f(35.0f, 35.0f, bZ);
            glVertex3f(35.0f, 50.0f,bZ);
    
            // Bottom Panel
            glVertex3f(-35.0f, -35.0f, bZ);
            glVertex3f(-35.0f, -50.0f, bZ);
            glVertex3f(35.0f, -50.0f, bZ);
            glVertex3f(35.0f, -35.0f,bZ);
    	
            // Insides /////////////////////////////
        	glColor3f(0.75f, 0.75f, 0.75f);
    
            // Normal points up Y axis
            glNormal3f(0.0f, 1.0f, 0.0f);
            glVertex3f(-35.0f, 35.0f, fZ);
            glVertex3f(35.0f, 35.0f, fZ);
            glVertex3f(35.0f, 35.0f, bZ);
            glVertex3f(-35.0f,35.0f,bZ);
    		
            // Bottom section
            glNormal3f(0.0f, 1.0f, 0.0f);
            glVertex3f(-35.0f, -35.0f, fZ);
            glVertex3f(-35.0f, -35.0f, bZ);
            glVertex3f(35.0f, -35.0f, bZ);
            glVertex3f(35.0f, -35.0f, fZ);
    
            // Left section
            glNormal3f(1.0f, 0.0f, 0.0f);
            glVertex3f(-35.0f, 35.0f, fZ);
            glVertex3f(-35.0f, 35.0f, bZ);
            glVertex3f(-35.0f, -35.0f, bZ);
            glVertex3f(-35.0f, -35.0f, fZ);
    
            // Right Section
            glNormal3f(-1.0f, 0.0f, 0.0f);
            glVertex3f(35.0f, 35.0f, fZ);
            glVertex3f(35.0f, -35.0f, fZ);
            glVertex3f(35.0f, -35.0f, bZ);
            glVertex3f(35.0f, 35.0f, bZ);
        glEnd();
    
        glFrontFace(GL_CCW);		// Counter clock-wise polygons face out
    
        // Restore the matrix state
        glPopMatrix();
    
        // Buffer swap
        glutSwapBuffers();
        }
    
    
    
    int main(int argc, char *argv[])
        {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
        glutInitWindowSize(800, 600);
        glutCreateWindow("Orthographic Projection");
        glutReshapeFunc(ChangeSize);
        glutSpecialFunc(SpecialKeys);
        glutDisplayFunc(RenderScene);
        SetupRC();
        glutMainLoop();
        
        return 0;
        }
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

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

    پیش فرض پاسخ : برنامه هایی گرافیكی ( OpenGL )

    برنامه ی قبلی در محیط سه بعدی ( Perspective )

    کد:
    // Perspect.c
    // Demonstrates Perspective Projection
    // OpenGL SuperBible
    // Richard S. Wright Jr.
    #include "../../Common/OpenGLSB.h"	// System and OpenGL Stuff
    
    // Rotation amounts
    static GLfloat xRot = 0.0f;
    static GLfloat yRot = 0.0f;
    
    
    // Change viewing volume and viewport.  Called when window is resized
    void ChangeSize(GLsizei w, GLsizei h)
        {
        GLfloat fAspect;
    
        // Prevent a divide by zero
        if(h == 0)
            h = 1;
    
        // Set Viewport to window dimensions
        glViewport(0, 0, w, h);
    
        fAspect = (GLfloat)w/(GLfloat)h;
    
        // Reset coordinate system
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
    
        // Produce the perspective projection
        gluPerspective(60.0f, fAspect, 1.0, 400.0);
    
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        }
    
    
    // This function does any needed initialization on the rendering
    // context.  Here it sets up and initializes the lighting for
    // the scene.
    void SetupRC()
        {
        // Light values and coordinates
        GLfloat  whiteLight[] = { 0.45f, 0.45f, 0.45f, 1.0f };
        GLfloat  sourceLight[] = { 0.25f, 0.25f, 0.25f, 1.0f };
        GLfloat	 lightPos[] = { -50.f, 25.0f, 250.0f, 0.0f };
    
        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
    
        // Enable lighting
        glEnable(GL_LIGHTING);
    
        // Setup and enable light 0
        glLightModelfv(GL_LIGHT_MODEL_AMBIENT,whiteLight);
        glLightfv(GL_LIGHT0,GL_AMBIENT,sourceLight);
        glLightfv(GL_LIGHT0,GL_DIFFUSE,sourceLight);
        glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
        glEnable(GL_LIGHT0);
    
        // Enable color tracking
        glEnable(GL_COLOR_MATERIAL);
    	
        // Set Material properties to follow glColor values
        glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
    
        // Black blue background
        glClearColor(0.0f, 0.0f, 0.0f, 1.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;
                    
            xRot = (GLfloat)((const int)xRot % 360);
            yRot = (GLfloat)((const int)yRot % 360);
    
    	// Refresh the Window
    	glutPostRedisplay();
    	}
    
    
    // Called to draw scene
    void RenderScene(void)
        {
        float fZ,bZ;
    
        // Clear the window with current clearing color
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        fZ = 100.0f;
        bZ = -100.0f;
    
        // Save the matrix state and do the rotations
        glPushMatrix();
        glTranslatef(0.0f, 0.0f, -300.0f);
        glRotatef(xRot, 1.0f, 0.0f, 0.0f);
        glRotatef(yRot, 0.0f, 1.0f, 0.0f);
    
        // Set material color, Red
        glColor3f(1.0f, 0.0f, 0.0f);
    
        // Front Face ///////////////////////////////////
        glBegin(GL_QUADS);
            // Pointing straight out Z
            glNormal3f(0.0f, 0.0f, 1.0f);	
    
            // Left Panel
            glVertex3f(-50.0f, 50.0f, fZ);
            glVertex3f(-50.0f, -50.0f, fZ);
            glVertex3f(-35.0f, -50.0f, fZ);
            glVertex3f(-35.0f,50.0f,fZ);
    
            // Right Panel
            glVertex3f(50.0f, 50.0f, fZ);
            glVertex3f(35.0f, 50.0f, fZ);
            glVertex3f(35.0f, -50.0f, fZ);
            glVertex3f(50.0f,-50.0f,fZ);
    
            // Top Panel
            glVertex3f(-35.0f, 50.0f, fZ);
            glVertex3f(-35.0f, 35.0f, fZ);
            glVertex3f(35.0f, 35.0f, fZ);
            glVertex3f(35.0f, 50.0f,fZ);
    
            // Bottom Panel
            glVertex3f(-35.0f, -35.0f, fZ);
            glVertex3f(-35.0f, -50.0f, fZ);
            glVertex3f(35.0f, -50.0f, fZ);
            glVertex3f(35.0f, -35.0f,fZ);
    
            // Top length section ////////////////////////////
            // Normal points up Y axis
            glNormal3f(0.0f, 1.0f, 0.0f);
            glVertex3f(-50.0f, 50.0f, fZ);
            glVertex3f(50.0f, 50.0f, fZ);
            glVertex3f(50.0f, 50.0f, bZ);
            glVertex3f(-50.0f,50.0f,bZ);
    		
            // Bottom section
            glNormal3f(0.0f, -1.0f, 0.0f);
            glVertex3f(-50.0f, -50.0f, fZ);
            glVertex3f(-50.0f, -50.0f, bZ);
            glVertex3f(50.0f, -50.0f, bZ);
            glVertex3f(50.0f, -50.0f, fZ);
    
            // Left section
            glNormal3f(1.0f, 0.0f, 0.0f);
            glVertex3f(50.0f, 50.0f, fZ);
            glVertex3f(50.0f, -50.0f, fZ);
            glVertex3f(50.0f, -50.0f, bZ);
            glVertex3f(50.0f, 50.0f, bZ);
    
            // Right Section
            glNormal3f(-1.0f, 0.0f, 0.0f);
            glVertex3f(-50.0f, 50.0f, fZ);
            glVertex3f(-50.0f, 50.0f, bZ);
            glVertex3f(-50.0f, -50.0f, bZ);
            glVertex3f(-50.0f, -50.0f, fZ);
        glEnd();
    
        glFrontFace(GL_CW);		// clock-wise polygons face out
    
        glBegin(GL_QUADS);
            // Back section
            // Pointing straight out Z
            glNormal3f(0.0f, 0.0f, -1.0f);	
    
            // Left Panel
            glVertex3f(-50.0f, 50.0f, bZ);
            glVertex3f(-50.0f, -50.0f, bZ);
            glVertex3f(-35.0f, -50.0f, bZ);
            glVertex3f(-35.0f,50.0f,bZ);
    
            // Right Panel
            glVertex3f(50.0f, 50.0f, bZ);
            glVertex3f(35.0f, 50.0f, bZ);
            glVertex3f(35.0f, -50.0f, bZ);
            glVertex3f(50.0f,-50.0f,bZ);
    
            // Top Panel
            glVertex3f(-35.0f, 50.0f, bZ);
            glVertex3f(-35.0f, 35.0f, bZ);
            glVertex3f(35.0f, 35.0f, bZ);
            glVertex3f(35.0f, 50.0f,bZ);
    
            // Bottom Panel
            glVertex3f(-35.0f, -35.0f, bZ);
            glVertex3f(-35.0f, -50.0f, bZ);
            glVertex3f(35.0f, -50.0f, bZ);
            glVertex3f(35.0f, -35.0f,bZ);
    	
            // Insides /////////////////////////////
        	glColor3f(0.75f, 0.75f, 0.75f);
    
            // Normal points up Y axis
            glNormal3f(0.0f, 1.0f, 0.0f);
            glVertex3f(-35.0f, 35.0f, fZ);
            glVertex3f(35.0f, 35.0f, fZ);
            glVertex3f(35.0f, 35.0f, bZ);
            glVertex3f(-35.0f,35.0f,bZ);
    		
            // Bottom section
            glNormal3f(0.0f, 1.0f, 0.0f);
            glVertex3f(-35.0f, -35.0f, fZ);
            glVertex3f(-35.0f, -35.0f, bZ);
            glVertex3f(35.0f, -35.0f, bZ);
            glVertex3f(35.0f, -35.0f, fZ);
    
            // Left section
            glNormal3f(1.0f, 0.0f, 0.0f);
            glVertex3f(-35.0f, 35.0f, fZ);
            glVertex3f(-35.0f, 35.0f, bZ);
            glVertex3f(-35.0f, -35.0f, bZ);
            glVertex3f(-35.0f, -35.0f, fZ);
    
            // Right Section
            glNormal3f(-1.0f, 0.0f, 0.0f);
            glVertex3f(35.0f, 35.0f, fZ);
            glVertex3f(35.0f, -35.0f, fZ);
            glVertex3f(35.0f, -35.0f, bZ);
            glVertex3f(35.0f, 35.0f, bZ);
        glEnd();
    
        glFrontFace(GL_CCW);		// Counter clock-wise polygons face out
    
        // Restore the matrix state
        glPopMatrix();
    
        // Buffer swap
        glutSwapBuffers();
        }
    
    
    
    int main(int argc, char *argv[])
        {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
        glutInitWindowSize(800, 600);
        glutCreateWindow("Perspective Projection");
        glutReshapeFunc(ChangeSize);
        glutSpecialFunc(SpecialKeys);
        glutDisplayFunc(RenderScene);
        SetupRC();
        glutMainLoop();
        
        return 0;
        }
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

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

    پیش فرض پاسخ : برنامه هایی گرافیكی ( OpenGL )

    برنامه ای كه گردش زمین و ماه رو به دور خورشید نمایش داده با جلوه های نور پردازی و سه بعدی

    کد:
    // Solar.c
    // OpenGL SuperBible
    // Demonstrates OpenGL nested coordinate transformations
    // and perspective
    // Program by Richard S. Wright Jr.
    
    #include "../../Common/OpenGLSB.h"	// System and OpenGL Stuff
    #include <math.h>
    
    
    // Lighting values
    GLfloat  whiteLight[] = { 0.2f, 0.2f, 0.2f, 1.0f };
    GLfloat  sourceLight[] = { 0.8f, 0.8f, 0.8f, 1.0f };
    GLfloat	 lightPos[] = { 0.0f, 0.0f, 0.0f, 1.0f };
    
    
    // Called to draw scene
    void RenderScene(void)
    	{
    	// Earth and Moon angle of revolution
    	static float fMoonRot = 0.0f;
    	static float fEarthRot = 0.0f;
    
    	// Clear the window with current clearing color
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    	// Save the matrix state and do the rotations
    	glMatrixMode(GL_MODELVIEW);
    	glPushMatrix();
    
    	// Translate the whole scene out and into view	
    	glTranslatef(0.0f, 0.0f, -300.0f);	
    	
    	// Set material color, Red
    	// Sun
            glDisable(GL_LIGHTING);
    	glColor3ub(255, 255, 0);
    	glutSolidSphere(15.0f, 30, 17);
            glEnable(GL_LIGHTING);
    
    	// Move the light after we draw the sun!
    	glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
    
    	// Rotate coordinate system
    	glRotatef(fEarthRot, 0.0f, 1.0f, 0.0f);
    
    	// Draw the Earth
    	glColor3ub(0,0,255);
    	glTranslatef(105.0f,0.0f,0.0f);
    	glutSolidSphere(15.0f, 30, 17);
    
    
    	// Rotate from Earth based coordinates and draw Moon
    	glColor3ub(200,200,200);
    	glRotatef(fMoonRot,0.0f, 1.0f, 0.0f);
    	glTranslatef(30.0f, 0.0f, 0.0f);
    	fMoonRot+= 15.0f;
    	if(fMoonRot > 360.0f)
    		fMoonRot = 0.0f;
    
    	glutSolidSphere(6.0f, 30, 17);
    
    	// Restore the matrix state
    	glPopMatrix();	// Modelview matrix
    
    
    	// Step earth orbit 5 degrees
    	fEarthRot += 5.0f;
    	if(fEarthRot > 360.0f)
    		fEarthRot = 0.0f;
    
    	// Show the image
    	glutSwapBuffers();
    	}
    
    
    // This function does any needed initialization on the rendering
    // context. 
    void SetupRC()
    	{
    	// Light values and coordinates
    	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
    
    	// Enable lighting
    	glEnable(GL_LIGHTING);
    
    	// Setup and enable light 0
    	glLightModelfv(GL_LIGHT_MODEL_AMBIENT,whiteLight);
    	glLightfv(GL_LIGHT0,GL_DIFFUSE,sourceLight);
    	glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
    	glEnable(GL_LIGHT0);
    
    	// Enable color tracking
    	glEnable(GL_COLOR_MATERIAL);
    	
    	// Set Material properties to follow glColor values
    	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
    
    	// Black blue background
    	glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
        }
    
    
    void TimerFunc(int value)
        {
        glutPostRedisplay();
        glutTimerFunc(100, TimerFunc, 1);
        }
    
    void ChangeSize(int w, int h)
        {
        GLfloat fAspect;
    
        // Prevent a divide by zero
        if(h == 0)
            h = 1;
    
        // Set Viewport to window dimensions
        glViewport(0, 0, w, h);
    
        // Calculate aspect ratio of the window
        fAspect = (GLfloat)w/(GLfloat)h;
    
        // Set the perspective coordinate system
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
    
        // field of view of 45 degrees, near and far planes 1.0 and 425
        gluPerspective(45.0f, fAspect, 1.0, 425.0);
    
        // Modelview matrix reset
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        }
    
    
    int main(int argc, char* argv[])
    	{
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
            glutInitWindowSize(800, 600);
    	glutCreateWindow("Earth/Moon/Sun System");
    	glutReshapeFunc(ChangeSize);
    	glutDisplayFunc(RenderScene);
            glutTimerFunc(250, TimerFunc, 1);
    	SetupRC();
    	glutMainLoop();
    
    	return 0;
    	}
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

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

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

در حال حاضر 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

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

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

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