السلام عليكم ورحمة الله وبركاته ,
كيف أخباركم :)
لديّ عن طريق OpenGL ، رسم دالّة جبريّة ثم جعلها متكررة في كل صفحة OpenGL
رسمت الدالة ولكنها لا تتكرر أبدا !
يبدو أني استخدمت جملة التكرار for loop بشكل غير صحيح أو في غير موضعها
هل مِن أحد يدلّني على موضع الخطأ ؟ :)
#include <windows.h>
#include <math.h>
#include <gl/GL.h>
#include <gl/GLU.h>
#include <gl/GLUT.h>
const float pi = 3.14159265358979;
//--------------- setWindow ---------------------
void setWindow(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(left*6, right*6, bottom*6, top*6);
}
//---------------- setViewport ------------------
void setViewport(int left, int right, int width, int height)
{
GLfloat bottom = 0.5;
GLfloat top = 1.5;
glViewport(left, bottom, (right - left), (top - bottom));
}
//<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void myDisplay(void)
{
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_LINE_STRIP);
for ( float i = 1.0 ; i < 60 ; i+=100 )
{
setViewport(i, i, i, i) ;
for( GLfloat x = -4.0 ; x < 4.0 ; x += 0.1 ) // draw the plot
if ( x==0.0 )
glVertex2f( 0.0 , 1.0 ) ;
else
glVertex2f( x , sin(pi * x) / (pi * x) ) ;
glEnd();
glFlush();
}
}
//<<<<<<<<<<<<<< myInit >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void myInit(void)
{
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0f,0.0f,1.0f);
glLineWidth(2.0);
}
//<<<<<<<<<<<<<<main>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(100,150);
glutCreateWindow("Sinc Function");
glutDisplayFunc(myDisplay);
myInit();
setWindow(-5.0, 5.0, -0.3, 1.0);
setViewport(0, 640, 0, 480);
glutMainLoop();
}أتمنى أن يزيد هذا الموضوع حصيلتكم كما أنه أثرى حصيلتي أيضا :)
