السلام عليكم و رحمة الله و بركاته
لدي هذا الكود الذي يقوم بمهام بسيطة مثل : اذا ضغطنا على حرف r يتحول لون المثلث المرسوم للون الاحمر
لكن هذا التغيير لا يظهر بشكل مباشر بعد الضغط حيث اني احتاج الى تغيير حجم النافذة يدويا وقت التشغيل حتى يظهر اللون الجديد
فما المشكلة ؟
ها هو الكود:
//#include "stdafx.h"
#include <iostream.h>
#include "gl/glut.h"
float r, g, b = 1;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(r,g,b);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
glutSwapBuffers();
}
void mykeyboard(unsigned char k, int
mouseX, int mouseY)
{
switch (k)
{
case 'R':
case 'r':
r= 1, g=0, b=0;
break;
case 'G':
case 'g':
r= 0, g=1, b=0;
break;
case 'B':
case 'b':
r= 0, g=0, b=1;
break;
case 27:
exit(0);
break;
//default: /* Otherwise keep going */
//return;
}
}
void myspecial (int key, int x, int y)
{
if (key=GLUT_KEY_F9)
glutFullScreen();
}
void mymouse (int button, int state, int
x, int y)
{
if (button== GLUT_LEFT_BUTTON &&
state== GLUT_DOWN)
cout<<x<<" "<<y<<endl;
}
void ProcessPMotion ( int x, int y)
{
glClearColor(0.9, 0.9, 1.0,1.0);
}
void processMotion ( int x, int y)
{
glClearColor(0.0, 0.0, 0.0,1.0);
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE);
glutCreateWindow(" First OGL Program");
glutDisplayFunc(display);
glutKeyboardFunc(mykeyboard);
glutSpecialFunc(myspecial);
glutPassiveMotionFunc(ProcessPMotion);
glutMotionFunc(processMotion);
glutMainLoop();
return 0;
}