Bonjour !

je me mets tout doucement au C++ et aux classes.
Le franchissement du C au C++ n'est pas encore vraiment acquis...
et je m y attelles pour un projet concret...

Je voudrais créer une classe d'objets Open GL pour créer plusieurs surfaces avec des images dedans.

J'ai besoin de laisser à l utilisateur sa définition de chaque surface (triangle, carré, cercle, ou bien grille de n coordonnées), qu'il puisse éditer à la souris ou au clavier chaque point.

J'utilises pour l'OpenGL la facon de faire de ce livre (vao, vbo), car à terme, il y aura besoin pour l utilisateur de manipuler aussi ses shaders.

Actuellement je buttes sur 2 choses:
- le passage et l'écriture de tableaux multidiemensionnels ( GLdouble Points[128][3] pour x y et z)
- l'utilisation dans une fonction d'une donnée de la classe ( par ex NbPoints pour travailler sur des boucles de traitement).

J'en suis là, et je crois que j'ai besoin d'un coup de main pour comprendre comment manipuler les tableaux avec les classes...

voilà


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
 
class  Surface
{
public:
    string Name;
    int ID;
    int NbPoints=3;//nbre points of the geometry, minima 3
    GLdouble Point[128][3];//3d vector
    GLuint VAO;
    GLuint VBO;
    GLdouble  Color[3];
 
    Surface();
    Surface(double * Points);
 
    GLdouble getPoints() const;
    void setPoints(GLdouble * Points);
 
 
    //geometry
    /* GL shader objects for vertex and fragment shader [components] */
	GLuint vs, fs;
	/* GL shader programme object [combined, to link] */
	GLuint shader_programme;
 
	/* these are the strings of code for the shaders
	the vertex shader positions each vertex point */
	const char* vertex_shader =
	"#version 410\n"
	"in vec3 vp;"
	"void main () {"
	"	gl_Position = vec4 (vp, 1.0);"
	"}";
	/* the fragment shader colours each fragment (pixel-sized area of the
	triangle) */
	const char* fragment_shader =
	"#version 410\n"
	"out vec4 frag_colour;"
	"void main () {"
	"	frag_colour = vec4 (0.5, 0.0, 0.5, 1.0);"
	"}";
 
 
/* a vertex buffer object (VBO) is created here. this stores an array of data
	on the graphics adapter's memory. in our case - the vertex points */
    void init_VBO()
    {
    glGenBuffers (1, &VBO);
	glBindBuffer (GL_ARRAY_BUFFER, VBO);
	glBufferData (GL_ARRAY_BUFFER, 9 * sizeof (GLfloat), Points, GL_STATIC_DRAW);
    }
/* the vertex array object (VAO) is a little descriptor that defines which
	data from vertex buffer objects should be used as input variables to vertex
	shaders. in our case - use our only VBO, and say 'every three floats is a
	variable' */
    void init_VAO()
    {
	glGenVertexArrays (1, &VAO);
	glBindVertexArray (VAO);
	glEnableVertexAttribArray (0);
	glBindBuffer (GL_ARRAY_BUFFER, VBO);
	glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
    }
	/* here we copy the shader strings into GL shaders, and compile them. we then
	create an executable shader 'program' and attach both of the compiled shaders.
	we link this, which matches the outputs of the vertex shader to the inputs of
	the fragment shader, etc. and it is then ready to use */
	void init_Shader()
	{
	vs = glCreateShader (GL_VERTEX_SHADER);
	glShaderSource (vs, 1, &vertex_shader, NULL);
	glCompileShader (vs);
	fs = glCreateShader (GL_FRAGMENT_SHADER);
	glShaderSource (fs, 1, &fragment_shader, NULL);
	glCompileShader (fs);
	shader_programme = glCreateProgram ();
	glAttachShader (shader_programme, fs);
	glAttachShader (shader_programme, vs);
	glLinkProgram (shader_programme);
	}
 
	void Use_Program()
	{
        glUseProgram (shader_programme);
	glBindVertexArray (VAO);
	/* draw points 0-3 from the currently bound VAO with current in-use shader*/
	glColor4f(1.0, 1.0, 1.0,0.5);
        glDrawArrays (GL_TRIANGLES, 0, NbPoints);
	}
 
};
 
 
Surface::Surface()
{
 
}
 
Surface::Surface(double *points)
{
 
 
}
 
 
void Surface::setPoints( double  * Points_)
{
 
}