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

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

توجه داشته باشید، در صورتی که عضو سایت نباشید نمی توانید از تمامی امکانات و خدمات سایت استفاده کنید.
صفحه 3 از 14 نخستنخست 12345678910111213 ... آخرینآخرین
نمایش نتایج: از شماره 21 تا 30 , از مجموع 137

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

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

    پیش فرض

    کد:
    // Linesw.c
    // OpenGL SuperBible, Chapter 4
    // Demonstrates primative GL_LINES with line widths
    // 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;
    
    
    // Called to draw scene
    void RenderScene(void)
    	{
    	GLfloat y;					// Storeage for varying Y coordinate
    	GLfloat fSizes[2];			// Line width range metrics
    	GLfloat fCurrSize;			// Save current size
    
    
    	// 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);
    
    	// Get line size metrics and save the smallest value
    	glGetFloatv(GL_LINE_WIDTH_RANGE,fSizes);
    	fCurrSize = fSizes[0];
    
    	// Step up Y axis 20 units at a time	
    	for(y = -90.0f; y < 90.0f; y += 20.0f)
    		{
    		// Set the line width
    		glLineWidth(fCurrSize);
    
    		// Draw the line
    		glBegin(GL_LINES);
    			glVertex2f(-80.0f, y);
    			glVertex2f(80.0f, y);	
    		glEnd();
    
    		// Increase the line width
    		fCurrSize += 1.0f;
    		}
    
    
    	// 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 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();
    	}
    
    int main(int argc, char* argv[])
    	{
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    	glutCreateWindow("Line Width Example");
    	glutReshapeFunc(ChangeSize);
    	glutSpecialFunc(SpecialKeys);
    	glutDisplayFunc(RenderScene);
    	SetupRC();
    	glutMainLoop();
    
    	return 0;
    	}
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

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

    پیش فرض

    کد:
    // Lstipple.c
    // OpenGL SuperBible, Chapter 4
    // Demonstrates line stippling
    // 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;
    
    
    // Called to draw scene
    void RenderScene(void)
    	{
    	GLfloat y;					// Storeage for varying Y coordinate
    	GLint factor = 3;			// Stippling factor
    	GLushort pattern = 0x5555;	// Stipple pattern
    	
    
    	// 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);
    
    
    
    	// Step up Y axis 20 units at a time	
    	for(y = -90.0f; y < 90.0f; y += 20.0f)
    		{
    		// Reset the repeat factor and pattern
    		glLineStipple(factor,pattern);
    
    		// Draw the line
    		glBegin(GL_LINES);
    			glVertex2f(-80.0f, y);
    			glVertex2f(80.0f, y);	
    		glEnd();
    
    		factor++;
    		}
    
    
    	// 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);
            
            // Enable Stippling
    	glEnable(GL_LINE_STIPPLE);
    	}
    
    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 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();
    	}
    
    int main(int argc, char* argv[])
    	{
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    	glutCreateWindow("Stippled Line Example");
    	glutReshapeFunc(ChangeSize);
    	glutSpecialFunc(SpecialKeys);
    	glutDisplayFunc(RenderScene);
    	SetupRC();
    	glutMainLoop();
    
    	return 0;
    	}
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

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

    پیش فرض

    کد:
    // LStrips.c
    // OpenGL SuperBible, Chapter 4
    // Demonstrates primative GL_LINE_STRIP
    // 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;
    
    
    // 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_LINE_STRIP);
    
    	z = -50.0f;
    	for(angle = 0.0f; angle <= (2.0f*3.1415f)*3.0f; angle += 0.1f)
    		{
    		x = 50.0f*sin(angle);
    		y = 50.0f*cos(angle);
    	
    		// Specify the point and move the Z value up a little	
    		glVertex3f(x, y, z);
    		z += 0.5f;
    		}
    
    	// 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);
    	}
    
    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 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();
    	}
    
    int main(int argc, char* argv[])
    	{
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    	glutCreateWindow("Line Strips Example");
    	glutReshapeFunc(ChangeSize);
    	glutSpecialFunc(SpecialKeys);
    	glutDisplayFunc(RenderScene);
    	SetupRC();
    	glutMainLoop();
    
    	return 0;
    	}
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

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

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

    کد:
    // Points.c
    // OpenGL SuperBible, Chapter 3
    // Demonstrates OpenGL Primative GL_POINTS
    // 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;
    
    
    // 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_POINTS);
    
    	z = -50.0f;
    	for(angle = 0.0f; angle <= (2.0f*GL_PI)*3.0f; angle += 0.1f)
    		{
    		x = 50.0f*sin(angle);
    		y = 50.0f*cos(angle);
    	
    		// Specify the point and move the Z value up a little	
    		glVertex3f(x, y, z);
    		z += 0.5f;
    		}
    
    	// 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);
    	}
    
    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("Points Example");
    	glutReshapeFunc(ChangeSize);
    	glutSpecialFunc(SpecialKeys);
    	glutDisplayFunc(RenderScene);
    	SetupRC();
    	glutMainLoop();
    
    	return 0;
    	}
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

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

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

    کد:
    // Pointsz.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;
    
    
    // Called to draw scene
    void RenderScene(void)
    	{
    	GLfloat x,y,z,angle; // Storeage for coordinates and angles
    	GLfloat sizes[2];	 // Store supported point size range
    	GLfloat step;		 // Store supported point size increments
    	GLfloat curSize;	 // Store current size
    
    	// 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);
    
    	// Get supported point size range and step size
    	glGetFloatv(GL_POINT_SIZE_RANGE,sizes);
    	glGetFloatv(GL_POINT_SIZE_GRANULARITY,&step);
    	
    	// Set the initial point size
    	curSize = sizes[0];
    
    	// Set beginning z coordinate
    	z = -50.0f;
    
    	// Loop around in a circle three times
    	for(angle = 0.0f; angle <= (2.0f*3.1415f)*3.0f; angle += 0.1f)
    		{
    		// Calculate x and y values on the circle
    		x = 50.0f*sin(angle);
    		y = 50.0f*cos(angle);
    	
    		// Specify the point size before the primative is specified
    		glPointSize(curSize);
    
    		// Draw the point
    		glBegin(GL_POINTS);
    			glVertex3f(x, y, z);
    		glEnd();
    
    		// Bump up the z value and the point size
    		z += 0.5f;
    		curSize += step;
    		}
    
    	// Restore matrix state
    	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[])
    	{
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    	glutCreateWindow("Points Size Example");
    	glutReshapeFunc(ChangeSize);
    	glutSpecialFunc(SpecialKeys);
    	glutDisplayFunc(RenderScene);
    	SetupRC();
    	glutMainLoop();
    
    	return 0;
    	}
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

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

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

    برنامه ی Plygon Stippeling که تصویری را در داخل تصویر دیگر Stipple می کند.

    کد:
    // PStipple.c
    // OpenGL SuperBible, Chapter 3
    // Demonstrates OpenGL Polygon Stippling
    // 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;
    
    // Bitmap of camp fire
    GLubyte fire[128] = { 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, 0xc0,
    				   0x00, 0x00, 0x01, 0xf0,
    				   0x00, 0x00, 0x07, 0xf0,
    				   0x0f, 0x00, 0x1f, 0xe0,
    				   0x1f, 0x80, 0x1f, 0xc0,
    				   0x0f, 0xc0, 0x3f, 0x80,	
    				   0x07, 0xe0, 0x7e, 0x00,
    				   0x03, 0xf0, 0xff, 0x80,
    				   0x03, 0xf5, 0xff, 0xe0,
    				   0x07, 0xfd, 0xff, 0xf8,
    				   0x1f, 0xfc, 0xff, 0xe8,
    				   0xff, 0xe3, 0xbf, 0x70, 
    				   0xde, 0x80, 0xb7, 0x00,
    				   0x71, 0x10, 0x4a, 0x80,
    				   0x03, 0x10, 0x4e, 0x40,
    				   0x02, 0x88, 0x8c, 0x20,
    				   0x05, 0x05, 0x04, 0x40,
    				   0x02, 0x82, 0x14, 0x40,
    				   0x02, 0x40, 0x10, 0x80, 
    				   0x02, 0x64, 0x1a, 0x80,
    				   0x00, 0x92, 0x29, 0x00,
    				   0x00, 0xb0, 0x48, 0x00,
    				   0x00, 0xc8, 0x90, 0x00,
    				   0x00, 0x85, 0x10, 0x00,
    				   0x00, 0x03, 0x00, 0x00,
    				   0x00, 0x00, 0x10, 0x00 };
    				   
    
    // Called to draw scene
    void RenderScene(void)
    	{
    	// Clear the window
    	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);
    
    	// Begin the stop sign shape,
    	// use a standard polygon for simplicity
    	glBegin(GL_POLYGON);
    		glVertex2f(-20.0f, 50.0f);
    		glVertex2f(20.0f, 50.0f);
    		glVertex2f(50.0f, 20.0f);
    		glVertex2f(50.0f, -20.0f);
    		glVertex2f(20.0f, -50.0f);
    		glVertex2f(-20.0f, -50.0f);
    		glVertex2f(-50.0f, -20.0f);
    		glVertex2f(-50.0f, 20.0f);
    	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 red
    	glColor3f(1.0f, 0.0f, 0.0f);
    	
    	// Enable polygon stippling
    	glEnable(GL_POLYGON_STIPPLE);
    	
    	// Specify a specific stipple pattern
    	glPolygonStipple(fire);
    	}
    
    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("Polygon Stippling");
    	glutReshapeFunc(ChangeSize);
    	glutSpecialFunc(SpecialKeys);
    	glutDisplayFunc(RenderScene);
    	SetupRC();
    	glutMainLoop();
    
    	return 0;
    	}
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

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

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

    برنامه ی رسم تصویر پیوست به صورت انیمیشن.

    کد:
    // Scissor.c
    // OpenGL SuperBible, 3rd Edition
    // Richard S. Wright Jr.
    // rwright@starstonesoftware.com
    
    #include "../../Common/OpenGLSB.h"	// System and OpenGL Stuff
    #include <math.h>
    	
    ///////////////////////////////////////////////////////////
    // Called to draw scene
    void RenderScene(void)
    	{
            static GLdouble dRadius = 0.1;
            static GLdouble dAngle = 0.0;
            
            // Clear blue window
            glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
            
            if(dAngle == 0.0)
                glClear(GL_COLOR_BUFFER_BIT);
                    
            glBegin(GL_POINTS);
                glVertex2d(dRadius * cos(dAngle), dRadius * sin(dAngle));
            glEnd();
            
            dRadius *= 1.01;
            dAngle += 0.1;
            
            if(dAngle > 30.0)
                {
                dRadius = 0.1;
                dAngle = 0.0;
                }
            
            glFlush();
            }
    
    ///////////////////////////////////////////////////////////
    // Trigger a repaint
    void Timer(int value)
        {
        glutTimerFunc(50,Timer, 0);
        glutPostRedisplay();
        }
    
    
    ///////////////////////////////////////////////////////////
    // Set viewport and projection
    void ChangeSize(int w, int h)
    	{
    	// Prevent a divide by zero
    	if(h == 0)
    		h = 1;
    
    	// Set Viewport to window dimensions
            glViewport(0, 0, w, h);
    
    
    	// Set the perspective coordinate system
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    
    	// Set 2D Coordinate system
    	gluOrtho2D(-4.0, 4.0, -3.0, 3.0);
    
    	// Modelview matrix reset
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    	}
    
    
    ///////////////////////////////////////////////////////////
    // Program entry point
    int main(int argc, char* argv[])
    	{
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_RGB);
    	glutInitWindowSize(800,600);
    	glutCreateWindow("OpenGL Single Buffered");
    	glutReshapeFunc(ChangeSize);
    	glutDisplayFunc(RenderScene);
            glutTimerFunc(50,Timer, 0);
            glutMainLoop();
    
    	return 0;
    	}
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

  8. #28
    مدیر کـــــــل ســــایت
    رشته تحصیلی
    مهندسی کامپیوتر - نرم افزار
    اکانت شخصی
    ندارد
    نوشته ها
    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;
    	}
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

  9. #29
    مدیر کـــــــل ســــایت
    رشته تحصیلی
    مهندسی کامپیوتر - نرم افزار
    اکانت شخصی
    ندارد
    نوشته ها
    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;
        }
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

  10. #30
    مدیر کـــــــل ســــایت
    رشته تحصیلی
    مهندسی کامپیوتر - نرم افزار
    اکانت شخصی
    ندارد
    نوشته ها
    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;
    	}
    نخبه یعنی خودباوری انسان و پس از خود باوری کاری غیر ممکن نمی شود

صفحه 3 از 14 نخستنخست 12345678910111213 ... آخرینآخرین

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

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

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

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

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

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