J'ai suivi plusieurs tutoriels et je ne comprends pas pourquoi ce code n'affiche rien.Pourquoi ce code n'affiche rien à l'écran
S'il vous plaît ne pas que LoadShaders fonctionne très bien.
J'ai fait un copier-coller, donc je ne pense pas que le problème vient de là ...
#include <iostream>
#include <fstream>
#include <vector>
#include <GL/glew.h>
#include <GL/gl.h>
#include <GLFW/glfw3.h>
GLFWwindow* window;
int main(int argc, const char * argv[])
{
if(!glfwInit())
{
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // We want OpenGL 3.3
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
window = glfwCreateWindow(640, 480, "Test1", NULL, NULL);
if(window == NULL)
{
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = true; // Needed for core profile
if (glewInit() != GLEW_OK)
{
return -1;
}
GLuint programID = LoadShaders("SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader");
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
glClearColor(0.0f, 1.0f, 1.0f, 1.0f);
do
{
glfwPollEvents();
glUseProgram(programID);
float vertices[] = {-0.5, -0.5, 0.0, 0.5, 0.5, -0.5};
glClear(GL_COLOR_BUFFER_BIT);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glfwSwapBuffers(window);
}
while(glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0);
glfwTerminate();
return 0;
}
Merci pour votre aide
Note:
Voici SimpleFragmentShader.fragmentshader :
#version 330 core
out vec3 color;
void main()
{
color = vec3(1,0,0);
}
Et voici SimpleVertexShader.vertexshader:
#version 330 core
layout(location = 0) in vec3 vertexPosition_modelspace;
void main()
{
gl_Position.xyz = vertexPosition_modelspace;
gl_Position.w = 1.0;
}
S'il vous plaît remarquer que j'ai aussi essayé de travailler sur les coordonnées 3D comme ceci:
float vertices[] = {-0.5, -0.5,0.0, 0.0, 0.5,0.0, 0.5, -0.5,0.0};
glClear(GL_COLOR_BUFFER_BIT);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
Si cela ne * pas * afficher * rien *, alors tout est bon, non? ;-) (Ceci est une allusion effrontée que vous avez une double négation dans le titre de vos questions qui ne devrait pas être là) – domsson
Je devrais voir un triangle – Bob5421
Est-ce que [glGetError()] (https: //www.khronos. org/registre/OpenGL-Refpages/es2.0/xhtml/glGetError.xml) vous dit quelque chose? Quelles étapes de débogage avez-vous prises? – zero298