bonjour. dans un petit code c++/opengl pour afficher deux rectangle rouge et vert,j'ai utilisé glreadpixel() pour récupérer la couleur des pixels colorés, le code est le suivant:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Source file for the OFF file viewer   ***Modifiée***
 
// INCLUDE FILES
 
#include <iostream> 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <assert.h>
 
#include <GL/glut.h>
#include <GL/glu.h>
#include <GL/gl.h>
 
#ifdef _WIN32
#include <windows.h>
#endif
#define DATA_WIDTH 20
#define DATA_HEIGHT 2000
 
using namespace std;
 
// TYPE DEFINITIONS
 
typedef struct data{
	unsigned char  r;
	unsigned char v;
	unsigned char b;
};
data datargb[DATA_WIDTH][DATA_HEIGHT]; 
 
 
// GLUT variables 
 
static int GLUTwindow = 0;
static int GLUTwindow_height = 800;
static int GLUTwindow_width = 800;
static int GLUTmouse[2] = { 0, 0 };
static int GLUTbutton[3] = { 0, 0, 0 };
static int GLUTarrows[4] = { 0, 0, 0, 0 };
static int GLUTmodifiers = 0;
 
// GLOBAL VARIABLES
 
float  midLar = ((float)GLUTwindow_width) / 2.0f;
float  midHau = ((float)GLUTwindow_height) / 2.0f;
 
FILE *f=NULL; char *fichier="C:/fichierRGB.txt";
 
// Display variables
 
static int scaling = 0;
static int translating = 0;
static int rotating = 0;
static float scale = 1.0;
static float center[3] = { 0.0, 0.0, 0.0 };
static float rotation[3] = { 0.0, 0.0, 0.0 };
static float translation[3] = { 0.0, 0.0, -4.0 };
 
 
void drawRectangle(void)
{
 
 
  // Set projection transformation
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity(); 
  gluPerspective(45.0, (GLfloat) GLUTwindow_width /(GLfloat) GLUTwindow_height, 0.1, 100.0);
 
  // Set camera transformation
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glTranslatef(translation[0], translation[1], translation[2]);
  glScalef(scale, scale, scale);
  glRotatef(rotation[0], 1.0, 0.0, 0.0);
  glRotatef(rotation[1], 0.0, 1.0, 0.0);
  glRotatef(rotation[2], 0.0, 0.0, 1.0);
  glTranslatef(-center[0], -center[1], -center[2]);
 
  // Clear window 
  glClearColor(.0, .0, .0, 1.0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glColor3f(.0,.0,.0); 
//rectangle rouge 
glColor3f(1.0,.0,.0);
glBegin(GL_POLYGON);
glVertex2f(.0,.0);
glVertex2f(0.2,.0); 
glVertex2f(0.2,1.0); 
glVertex2f(.0,1.0); 
glEnd(); 
rectangle vert
glColor3f(.0,1.0,.0);
glBegin(GL_POLYGON);
glVertex2f(0.201,0.0);
glVertex2f(0.4,0.0); 
glVertex2f(0.4,1.0); 
glVertex2f(0.201,1.0); 
glEnd();  
 
glutSwapBuffers(); 
 
 
glReadBuffer(GL_FRONT);
glReadPixels((int)(midLar),(int)(midHau),DATA_WIDTH,DATA_HEIGHT,GL_RGB,GL_UNSIGNED_BYTE,datargb); 
 
f=fopen(fichier,"w"); 
 
for(int k=0;k<3;k++)
{ 
for(int m=0;m<2000;m++)
{    
 fprintf(f,"[%d][%d]:  r:%d   g:%d   b:%d\n",k,m,(int)datargb[k][m].r,(int)datargb[k][m].v,(int)datargb[k][m].b);
}
}  
fclose(f);  
}    
 
void GLUTInit(int *argc, char **argv)
{
  // Open window 
  glutInit(argc, argv);
  glutInitWindowPosition(300, 100);
  glutInitWindowSize(GLUTwindow_width, GLUTwindow_height);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);  
  GLUTwindow = glutCreateWindow("OpenGL Viewer");
 
  // Initialize GLUT callback functions 
  glutDisplayFunc(drawRectangle); 
  // Initialize graphics modes 
  glEnable(GL_DEPTH_TEST);
}
 
 
int main(int argc, char **argv)
{  
  // Initialize GLUT
  GLUTInit(&argc, argv);  
  // Run GLUT interface 
  glutMainLoop();
  // Return success 
  return 0;
}

ma question est : quelle est la largeur et la hauteur adéquate de glreadpixel() pour récupérer seulement les couleurs rouge et vert (des deux rectangles sachant que les point des rectangle sont de type float ?

cordialement