Bonjour à tous,
j'ai fais un programme affichant un simple triangle avec une texture.
Je remarque cependant que la ram ne cèsse d'augmenter et je cherche à savoir pourquoi et comment limiter l'utilisation.

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
 
#include <GL\glew.h>
#include <SFML\Window.hpp>
#include <SFML\Graphics.hpp>
#include <glm\glm.hpp>
#include <glm\gtx\transform.hpp>
#include <glm\gtc\matrix_transform.hpp>
#include <iostream>
using namespace std;
using namespace glm;
struct Vector{
	glm::vec3 vertices;
	glm::vec2 coords;
};
void render();
extern const char* vertexShaderCode;
extern const char* fragmentShaderCode;
sf::Window window;
sf::Event event;
sf::Image image;
sf::Texture texture;
sf::ContextSettings settings;
bool running;
int main(void)
{
	glewInit();
	running = true;
	settings.depthBits = 24;
	settings.stencilBits = 8;
	settings.antialiasingLevel = 2;
	settings.majorVersion = 3;
	settings.minorVersion = 0;
	window.create(sf::VideoMode(640, 480), "OpenGL", sf::Style::Default, settings);
	window.setFramerateLimit(24);
	if (!image.loadFromFile("imagetest.jpg"))
	{
		running = false;
	}
	image.flipVertically();
	if (!texture.loadFromImage(image))
	{
		running = false;
	}
	while (running)
	{
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
			{
				running = false;
				return 0;
			}
		}
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		//render
		render();
		window.display();
	}
	return 0;
}
void render()
{
    sf::Texture::bind(&texture);
	Vector verts[] = {
		vec3(+0.0f, +0.0f, +0.0f),
		vec2(+0.0f, +0.0f),
 
		vec3(+1.0f, +1.0f, +0.0f),
		vec2(+1.0f, +1.0f),
 
		vec3(-1.0f, +1.0f, +0.0f),
		vec2(-1.0f, +1.0f),
 
		vec3(-1.0f, -1.0f, +0.0f),
		vec2(-1.0f, -1.0f),
 
		vec3(+1.0f, -1.0f, +0.0f),
		vec2(+1.0f, -1.0f),
	};
	GLuint glArrayBuffer;
	glGenBuffers(1, &glArrayBuffer);
	glBindBuffer(GL_ARRAY_BUFFER, glArrayBuffer);
	glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 5, (char*)(sizeof(float) * 0));
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 5, (char*)(sizeof(float) * 3));
 
	GLuint glElementArrayBuffer;
	GLshort indices[] = { 0, 1, 2, 0, 3, 4 };
	glGenBuffers(1, &glElementArrayBuffer);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glElementArrayBuffer);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
	glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
 
	GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
	GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
 
	const char* adapter[1];
	adapter[0] = vertexShaderCode;
	glShaderSource(vertexShader, 1, adapter, 0);
	adapter[0] = fragmentShaderCode;
	glShaderSource(fragmentShader, 1, adapter, 0);
 
	glCompileShader(vertexShader);
	glCompileShader(fragmentShader);
 
	GLuint program = glCreateProgram();
	GLuint textureBind;
	glGenTextures(1, &textureBind);
	GLuint imageLocation = glGetUniformLocation(program, "image");
	glUniform1f(imageLocation, textureBind);
 
	glAttachShader(program, vertexShader);
	glAttachShader(program, fragmentShader);
	glLinkProgram(program);
 
	glUseProgram(program);
	glDeleteShader(vertexShader);
	glDeleteShader(fragmentShader);
 
	mat4 projectionMatrix = perspective(45.0f, (float)window.getSize().x / window.getSize().y, 0.1f, 10.0f) * translate(mat4(), vec3(0, 0, -5));
	mat4 translationMatrix = translate(mat4(), vec3(0.0f, 0.0f, 0.0f));
	mat4 rotationMatrixX = rotate(mat4(), 0.0f, vec3(1.0f,0.0f,0.0f));
	mat4 rotationMatrixY = rotate(mat4(), 0.0f, vec3(0.0f, 1.0f, 0.0f));
	mat4 rotationMatrixZ = rotate(mat4(), 0.0f, vec3(0.0f, 0.0f, 1.0f));
	mat4 fullTransform = projectionMatrix * translationMatrix * rotationMatrixX * rotationMatrixY * rotationMatrixZ;
	GLint fullTransformMatrix = glGetUniformLocation(program, "fullTransform");
	glUniformMatrix4fv(fullTransformMatrix, 1, GL_FALSE, &fullTransform[0][0]);
	sf::Texture::bind(NULL);
}
Voila, j'aimerais savoir ce qui ne va pas dans le code, je pense que c'est du à un élément qu'il ne faut pas mettre dans la boucle...
Merci d'avance,
Max.