
mush74
|
Voici un bout de code. Je suis newbie en C et openGL et pour couronner le tout je développe dans le RER...alors un peu d'indulgence svp ;-)
pour résumer, j'affiche une fenetre GLUT avec un fond de couleur. J'ajoute 6 cadrans de fond noir. La méthode employée n'est d'ailleurs pas élégante, mais j'ai pas trouvé mieux... Puis sur tout cela, je fait varier ici des graduations (ce n'est pas une aiguille sur ce bout de code, mais le principe est le même).
luhtor, tes remarques semblent interressantes, mais je n'ai pas du tout entendu parlé de timer ni de synchro verticale dans les docs que j'ai pu me procurer sur le net. Si tu as des infos...voire un bout de code qui explique ce principe...
int main(int argc, char **argv)
{
glutInitWindowSize(HSIZE, VSIZE);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(0, 0);
glutCreateWindow("EFIS");
glutInit();
glutDisplayFunc(efis_run);
glutKeyboardFunc(capteurs);
glutIdleFunc(data_process);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
// Fonction data_process : Simule l'entrée de signaux des capteurs
void data_process()
{
cap+=8; //ajout de +8° (tests)
efis_cap_move(cptposH[cap_pos], cptposV[cap_pos], CPT_SIZE, cap);
glutPostRedisplay();
glutSwapBuffers();
}
// Fonction efis_run : Affichage de l'EFIS
void efis_run()
{
efis_background();
glutSwapBuffers();
}
// Fonction glutInit : Initialisation fenêtre GLUT
void glutInit(void)
{
glShadeModel (GL_SMOOTH);
glEnable (GL_LINE_SMOOTH);
glEnable (GL_POLYGON_SMOOTH);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
glClear (GL_COLOR_BUFFER_BIT);
}
void reshape (int width, int height)
{
GLfloat w, h;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (width > height)
{
w = (6.0 * width) / height;
h = 6.0;
}
else
{
w = 6.0;
h = (6.0 * height) / width;
}
glOrtho(-w, w, -h, h, -1, 1);
glutPostRedisplay();
}
void efis_background()
{
glPushMatrix();
glClearColor(0.8, 0.8, 0.8, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
efisCircle(0 , 10/3 , CPT_SIZE, CPT_WIDTH);
efisCircle(-5, 10/3 , CPT_SIZE, CPT_WIDTH);
efisCircle(5, 10/3 , CPT_SIZE, CPT_WIDTH);
efisCircle(0 , -10/3 , CPT_SIZE, CPT_WIDTH);
efisCircle(5, -10/3 , CPT_SIZE, CPT_WIDTH);
efisCircle(-5, -10/3 , CPT_SIZE, CPT_WIDTH);
glPopMatrix();
}
// efisGrad : Draw graduations
void efisGrad(float x,float y,float r, float w, int g, int degStart, int degEnd)
{
float angle,x1,x2,y1,y2,incg;
if (degStart > degEnd)
{
incg = ((360-degStart)+degEnd)/(g-1);
}
else
{
incg = (degEnd-degStart)/(g-1);
}
if (degStart > degEnd) degStart = degStart-360;
// Graduations principales
glLineWidth(w);
glColor3f(1.0,1.0,1.0);
glBegin(GL_LINES);
for (angle=degStart;angle<=degEnd;angle+=incg)
{
x1 = r*sin(angle/RAD)+x;
y1 = r*cos(angle/RAD)+y;
x2 = (r-0.2)*sin(angle/RAD)+x;
y2 = (r-0.2)*cos(angle/RAD)+y;
glVertex2f(x1,y1);
glVertex2f(x2,y2);
}
glEnd();
// Graduations secondaires
glLineWidth(w/2);
glBegin(GL_LINES);
for (angle=degStart;angle<=degEnd;angle+=incg/5)
{
x1 = r*sin(angle/RAD)+x;
y1 = r*cos(angle/RAD)+y;
x2 = (r-0.1)*sin(angle/RAD)+x;
y2 = (r-0.1)*cos(angle/RAD)+y;
glVertex2f(x1,y1);
glVertex2f(x2,y2);
}
glEnd();
}
void print_stroke_string(void* font, char* s)
{
if (s && strlen(s)) {
while (*s) {
glutStrokeCharacter(font, *s);
s++;
}
}
}
void efis_cap_move(float x, float y, float r, float cap)
{
glPushMatrix();
glColor3f(1.0,1.0,1.0);
efisGrad(x, y, r, CPT_WIDTH, 9, cap, 360+cap);
glPopMatrix();
}
// efisCircle : Draw circle Center = x,y Ray = r Width = w
void efisCircle(float x,float y,float r, float w)
{
float angle,xc,yc;
glLineWidth(w);
glColor3f(1.0,1.0,1.0);
glBegin(GL_LINE_STRIP);
for (angle=0;angle<=360;angle+=0.1f)
{
xc = r*sin(angle/RAD)+x;
yc = r*cos(angle/RAD)+y;
glVertex2f(xc,yc);
}
glColor3f(0.0,0.0,0.0);
glBegin(GL_LINE_STRIP);
for (angle=0;angle<=360;angle+=0.1f)
{
xc = r*sin(angle/RAD)+x;
yc = r*cos(angle/RAD)+y;
glVertex2f(x,y);
glVertex2f(xc,yc);
}
glEnd();
}
|