OpenGL ignores Quads and makes them Triangles











up vote
3
down vote

favorite












This is the second time I'm making a game engine, but I'm a little stuck right now, since I cannot figure out why this is happening, no matter what object I send, OpenGL only draws a White Triangle on the center of the screen, like this.



I've even coppied my old code from my last engine on the Renderer and the Camera Objects, still acts the same, so I´m guessing it has something to do with the Render Script.



Renderer:



Renderer2D::Renderer2D(const Shader& shader) {
this->shader = shader;
this->Init();
}

Renderer2D::~Renderer2D() {
glDeleteVertexArrays(1, &this->QuadVAO);
}

void Renderer2D::Render(Texture & texture, iVec2 position, iVec2 size, float rotation, iVec3 color) {
this->shader.Use();
iMat4 model;

using namespace glm;
model = translate(model, iVec3(position.x, position.y, 0.0f));
/*
model = translate(model, iVec3(size.x * 0.5f, size.y * 0.5f, 0.0f));
model = rotate(model, rotation, iVec3(0.0f, 0.0f, 1.0f));
model = translate(model, iVec3(size.x * -0.5f, size.y * -0.5f, 0.0f));
*/
model = glm::scale(model, iVec3(size.x, size.y, 1.0f));

this->shader.SetMatrix4("model2D", model);
this->shader.SetVector3f("color2D", color);

glActiveTexture(GL_TEXTURE0);
texture.Bind();

glBindVertexArray(this->QuadVAO);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
}

void Renderer2D::Init() {
U16 VBO;

float vertices = {
// Pos // Tex
0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,

0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, 0.0f
};

glGenVertexArrays(1, &this->QuadVAO);
glGenBuffers(1, &VBO);

glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

glBindVertexArray(this->QuadVAO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}


Vertex Shader:



#version 330 core
layout (location = 0) in vec4 vertex; // <vec2 position, vec2 texCoords>

out vec2 TexCoords;

uniform mat4 view2D;
uniform mat4 model2D;
uniform mat4 projection2D;

void main()
{
TexCoords = vertex.zw;
gl_Position = projection2D * view2D * mode2Dl * vec4(vertex.xy, 0.0, 1.0);
}




Edit:



Vertex Shader:



#version 330 core
layout (location = 0) in vec4 vertex; // <vec2 position, vec2 texCoords>

out vec2 TexCoords;

uniform mat4 view2D;
uniform mat4 model2D;
uniform mat4 projection2D;

void main()
{
TexCoords = vertex.zw;
gl_Position = projection2D * view2D * model2D * vec4(vertex.xy, 0.0, 1.0);
}


Fragment Shader:



#version 330 core
in vec2 TexCoords;
out vec4 color2D; //Fixed the error!

uniform sampler2D image2D;
uniform vec3 color2D;

void main()
{
color2D = vec4(color2D, 1.0) * texture(image2D, TexCoords);
}


Resources.cpp



Shader Resources::LoadShaderFromFile(const char * vertexSource, const char * fragmentSource) {
using namespace std;
string vertexCode;
string fragmentCode;

try {
ifstream vertexShaderFile(vertexSource);
ifstream fragmentShaderFile(fragmentSource);
stringstream vShaderStream, fShaderStream;

vShaderStream << vertexShaderFile.rdbuf();
fShaderStream << fragmentShaderFile.rdbuf();

vertexShaderFile.close();
fragmentShaderFile.close();

vertexCode = vShaderStream.str();
fragmentCode = fShaderStream.str();
}
catch (exception e) {
cout << "ERROR::SHADER: Failed to read shader files" << std::endl;
}

const char *vShaderCode = vertexCode.c_str();
const char *fShaderCode = fragmentCode.c_str();

Shader shader;
shader.Compile(vShaderCode, fShaderCode);

return shader;
}









share|improve this question
























  • What version of OpenGL are you running? Are you aware that as of OpenGL 3+ quads are deprecated?
    – Patrick
    Nov 9 at 2:27






  • 1




    @Patrick I just added Quads on the title because I´m trying to draw quads, but I´m Actually drawing 2 triangles next to each other, just updated the question with that code.
    – Aether
    Nov 9 at 2:33










  • Could you try changing the z coordinates of the triangles to -1.0f instead of 0.0f. I believe the triangle is clipping since positive z is out of screen.
    – Patrick
    Nov 9 at 2:44










  • @Patrick model = translate(model, iVec3(position.x, position.y, -1.0f)); Changed this line, is that what you mean?
    – Aether
    Nov 9 at 3:04










  • @Patrick I'm starting to think is a view port error or something since, no matter what coordinates I enter, triangle will always be the same position with no texture.
    – Aether
    Nov 9 at 3:04















up vote
3
down vote

favorite












This is the second time I'm making a game engine, but I'm a little stuck right now, since I cannot figure out why this is happening, no matter what object I send, OpenGL only draws a White Triangle on the center of the screen, like this.



I've even coppied my old code from my last engine on the Renderer and the Camera Objects, still acts the same, so I´m guessing it has something to do with the Render Script.



Renderer:



Renderer2D::Renderer2D(const Shader& shader) {
this->shader = shader;
this->Init();
}

Renderer2D::~Renderer2D() {
glDeleteVertexArrays(1, &this->QuadVAO);
}

void Renderer2D::Render(Texture & texture, iVec2 position, iVec2 size, float rotation, iVec3 color) {
this->shader.Use();
iMat4 model;

using namespace glm;
model = translate(model, iVec3(position.x, position.y, 0.0f));
/*
model = translate(model, iVec3(size.x * 0.5f, size.y * 0.5f, 0.0f));
model = rotate(model, rotation, iVec3(0.0f, 0.0f, 1.0f));
model = translate(model, iVec3(size.x * -0.5f, size.y * -0.5f, 0.0f));
*/
model = glm::scale(model, iVec3(size.x, size.y, 1.0f));

this->shader.SetMatrix4("model2D", model);
this->shader.SetVector3f("color2D", color);

glActiveTexture(GL_TEXTURE0);
texture.Bind();

glBindVertexArray(this->QuadVAO);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
}

void Renderer2D::Init() {
U16 VBO;

float vertices = {
// Pos // Tex
0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,

0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, 0.0f
};

glGenVertexArrays(1, &this->QuadVAO);
glGenBuffers(1, &VBO);

glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

glBindVertexArray(this->QuadVAO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}


Vertex Shader:



#version 330 core
layout (location = 0) in vec4 vertex; // <vec2 position, vec2 texCoords>

out vec2 TexCoords;

uniform mat4 view2D;
uniform mat4 model2D;
uniform mat4 projection2D;

void main()
{
TexCoords = vertex.zw;
gl_Position = projection2D * view2D * mode2Dl * vec4(vertex.xy, 0.0, 1.0);
}




Edit:



Vertex Shader:



#version 330 core
layout (location = 0) in vec4 vertex; // <vec2 position, vec2 texCoords>

out vec2 TexCoords;

uniform mat4 view2D;
uniform mat4 model2D;
uniform mat4 projection2D;

void main()
{
TexCoords = vertex.zw;
gl_Position = projection2D * view2D * model2D * vec4(vertex.xy, 0.0, 1.0);
}


Fragment Shader:



#version 330 core
in vec2 TexCoords;
out vec4 color2D; //Fixed the error!

uniform sampler2D image2D;
uniform vec3 color2D;

void main()
{
color2D = vec4(color2D, 1.0) * texture(image2D, TexCoords);
}


Resources.cpp



Shader Resources::LoadShaderFromFile(const char * vertexSource, const char * fragmentSource) {
using namespace std;
string vertexCode;
string fragmentCode;

try {
ifstream vertexShaderFile(vertexSource);
ifstream fragmentShaderFile(fragmentSource);
stringstream vShaderStream, fShaderStream;

vShaderStream << vertexShaderFile.rdbuf();
fShaderStream << fragmentShaderFile.rdbuf();

vertexShaderFile.close();
fragmentShaderFile.close();

vertexCode = vShaderStream.str();
fragmentCode = fShaderStream.str();
}
catch (exception e) {
cout << "ERROR::SHADER: Failed to read shader files" << std::endl;
}

const char *vShaderCode = vertexCode.c_str();
const char *fShaderCode = fragmentCode.c_str();

Shader shader;
shader.Compile(vShaderCode, fShaderCode);

return shader;
}









share|improve this question
























  • What version of OpenGL are you running? Are you aware that as of OpenGL 3+ quads are deprecated?
    – Patrick
    Nov 9 at 2:27






  • 1




    @Patrick I just added Quads on the title because I´m trying to draw quads, but I´m Actually drawing 2 triangles next to each other, just updated the question with that code.
    – Aether
    Nov 9 at 2:33










  • Could you try changing the z coordinates of the triangles to -1.0f instead of 0.0f. I believe the triangle is clipping since positive z is out of screen.
    – Patrick
    Nov 9 at 2:44










  • @Patrick model = translate(model, iVec3(position.x, position.y, -1.0f)); Changed this line, is that what you mean?
    – Aether
    Nov 9 at 3:04










  • @Patrick I'm starting to think is a view port error or something since, no matter what coordinates I enter, triangle will always be the same position with no texture.
    – Aether
    Nov 9 at 3:04













up vote
3
down vote

favorite









up vote
3
down vote

favorite











This is the second time I'm making a game engine, but I'm a little stuck right now, since I cannot figure out why this is happening, no matter what object I send, OpenGL only draws a White Triangle on the center of the screen, like this.



I've even coppied my old code from my last engine on the Renderer and the Camera Objects, still acts the same, so I´m guessing it has something to do with the Render Script.



Renderer:



Renderer2D::Renderer2D(const Shader& shader) {
this->shader = shader;
this->Init();
}

Renderer2D::~Renderer2D() {
glDeleteVertexArrays(1, &this->QuadVAO);
}

void Renderer2D::Render(Texture & texture, iVec2 position, iVec2 size, float rotation, iVec3 color) {
this->shader.Use();
iMat4 model;

using namespace glm;
model = translate(model, iVec3(position.x, position.y, 0.0f));
/*
model = translate(model, iVec3(size.x * 0.5f, size.y * 0.5f, 0.0f));
model = rotate(model, rotation, iVec3(0.0f, 0.0f, 1.0f));
model = translate(model, iVec3(size.x * -0.5f, size.y * -0.5f, 0.0f));
*/
model = glm::scale(model, iVec3(size.x, size.y, 1.0f));

this->shader.SetMatrix4("model2D", model);
this->shader.SetVector3f("color2D", color);

glActiveTexture(GL_TEXTURE0);
texture.Bind();

glBindVertexArray(this->QuadVAO);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
}

void Renderer2D::Init() {
U16 VBO;

float vertices = {
// Pos // Tex
0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,

0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, 0.0f
};

glGenVertexArrays(1, &this->QuadVAO);
glGenBuffers(1, &VBO);

glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

glBindVertexArray(this->QuadVAO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}


Vertex Shader:



#version 330 core
layout (location = 0) in vec4 vertex; // <vec2 position, vec2 texCoords>

out vec2 TexCoords;

uniform mat4 view2D;
uniform mat4 model2D;
uniform mat4 projection2D;

void main()
{
TexCoords = vertex.zw;
gl_Position = projection2D * view2D * mode2Dl * vec4(vertex.xy, 0.0, 1.0);
}




Edit:



Vertex Shader:



#version 330 core
layout (location = 0) in vec4 vertex; // <vec2 position, vec2 texCoords>

out vec2 TexCoords;

uniform mat4 view2D;
uniform mat4 model2D;
uniform mat4 projection2D;

void main()
{
TexCoords = vertex.zw;
gl_Position = projection2D * view2D * model2D * vec4(vertex.xy, 0.0, 1.0);
}


Fragment Shader:



#version 330 core
in vec2 TexCoords;
out vec4 color2D; //Fixed the error!

uniform sampler2D image2D;
uniform vec3 color2D;

void main()
{
color2D = vec4(color2D, 1.0) * texture(image2D, TexCoords);
}


Resources.cpp



Shader Resources::LoadShaderFromFile(const char * vertexSource, const char * fragmentSource) {
using namespace std;
string vertexCode;
string fragmentCode;

try {
ifstream vertexShaderFile(vertexSource);
ifstream fragmentShaderFile(fragmentSource);
stringstream vShaderStream, fShaderStream;

vShaderStream << vertexShaderFile.rdbuf();
fShaderStream << fragmentShaderFile.rdbuf();

vertexShaderFile.close();
fragmentShaderFile.close();

vertexCode = vShaderStream.str();
fragmentCode = fShaderStream.str();
}
catch (exception e) {
cout << "ERROR::SHADER: Failed to read shader files" << std::endl;
}

const char *vShaderCode = vertexCode.c_str();
const char *fShaderCode = fragmentCode.c_str();

Shader shader;
shader.Compile(vShaderCode, fShaderCode);

return shader;
}









share|improve this question















This is the second time I'm making a game engine, but I'm a little stuck right now, since I cannot figure out why this is happening, no matter what object I send, OpenGL only draws a White Triangle on the center of the screen, like this.



I've even coppied my old code from my last engine on the Renderer and the Camera Objects, still acts the same, so I´m guessing it has something to do with the Render Script.



Renderer:



Renderer2D::Renderer2D(const Shader& shader) {
this->shader = shader;
this->Init();
}

Renderer2D::~Renderer2D() {
glDeleteVertexArrays(1, &this->QuadVAO);
}

void Renderer2D::Render(Texture & texture, iVec2 position, iVec2 size, float rotation, iVec3 color) {
this->shader.Use();
iMat4 model;

using namespace glm;
model = translate(model, iVec3(position.x, position.y, 0.0f));
/*
model = translate(model, iVec3(size.x * 0.5f, size.y * 0.5f, 0.0f));
model = rotate(model, rotation, iVec3(0.0f, 0.0f, 1.0f));
model = translate(model, iVec3(size.x * -0.5f, size.y * -0.5f, 0.0f));
*/
model = glm::scale(model, iVec3(size.x, size.y, 1.0f));

this->shader.SetMatrix4("model2D", model);
this->shader.SetVector3f("color2D", color);

glActiveTexture(GL_TEXTURE0);
texture.Bind();

glBindVertexArray(this->QuadVAO);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
}

void Renderer2D::Init() {
U16 VBO;

float vertices = {
// Pos // Tex
0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,

0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, 0.0f
};

glGenVertexArrays(1, &this->QuadVAO);
glGenBuffers(1, &VBO);

glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

glBindVertexArray(this->QuadVAO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}


Vertex Shader:



#version 330 core
layout (location = 0) in vec4 vertex; // <vec2 position, vec2 texCoords>

out vec2 TexCoords;

uniform mat4 view2D;
uniform mat4 model2D;
uniform mat4 projection2D;

void main()
{
TexCoords = vertex.zw;
gl_Position = projection2D * view2D * mode2Dl * vec4(vertex.xy, 0.0, 1.0);
}




Edit:



Vertex Shader:



#version 330 core
layout (location = 0) in vec4 vertex; // <vec2 position, vec2 texCoords>

out vec2 TexCoords;

uniform mat4 view2D;
uniform mat4 model2D;
uniform mat4 projection2D;

void main()
{
TexCoords = vertex.zw;
gl_Position = projection2D * view2D * model2D * vec4(vertex.xy, 0.0, 1.0);
}


Fragment Shader:



#version 330 core
in vec2 TexCoords;
out vec4 color2D; //Fixed the error!

uniform sampler2D image2D;
uniform vec3 color2D;

void main()
{
color2D = vec4(color2D, 1.0) * texture(image2D, TexCoords);
}


Resources.cpp



Shader Resources::LoadShaderFromFile(const char * vertexSource, const char * fragmentSource) {
using namespace std;
string vertexCode;
string fragmentCode;

try {
ifstream vertexShaderFile(vertexSource);
ifstream fragmentShaderFile(fragmentSource);
stringstream vShaderStream, fShaderStream;

vShaderStream << vertexShaderFile.rdbuf();
fShaderStream << fragmentShaderFile.rdbuf();

vertexShaderFile.close();
fragmentShaderFile.close();

vertexCode = vShaderStream.str();
fragmentCode = fShaderStream.str();
}
catch (exception e) {
cout << "ERROR::SHADER: Failed to read shader files" << std::endl;
}

const char *vShaderCode = vertexCode.c_str();
const char *fShaderCode = fragmentCode.c_str();

Shader shader;
shader.Compile(vShaderCode, fShaderCode);

return shader;
}






c++ opengl glsl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 0:03

























asked Nov 9 at 2:18









Aether

295




295












  • What version of OpenGL are you running? Are you aware that as of OpenGL 3+ quads are deprecated?
    – Patrick
    Nov 9 at 2:27






  • 1




    @Patrick I just added Quads on the title because I´m trying to draw quads, but I´m Actually drawing 2 triangles next to each other, just updated the question with that code.
    – Aether
    Nov 9 at 2:33










  • Could you try changing the z coordinates of the triangles to -1.0f instead of 0.0f. I believe the triangle is clipping since positive z is out of screen.
    – Patrick
    Nov 9 at 2:44










  • @Patrick model = translate(model, iVec3(position.x, position.y, -1.0f)); Changed this line, is that what you mean?
    – Aether
    Nov 9 at 3:04










  • @Patrick I'm starting to think is a view port error or something since, no matter what coordinates I enter, triangle will always be the same position with no texture.
    – Aether
    Nov 9 at 3:04


















  • What version of OpenGL are you running? Are you aware that as of OpenGL 3+ quads are deprecated?
    – Patrick
    Nov 9 at 2:27






  • 1




    @Patrick I just added Quads on the title because I´m trying to draw quads, but I´m Actually drawing 2 triangles next to each other, just updated the question with that code.
    – Aether
    Nov 9 at 2:33










  • Could you try changing the z coordinates of the triangles to -1.0f instead of 0.0f. I believe the triangle is clipping since positive z is out of screen.
    – Patrick
    Nov 9 at 2:44










  • @Patrick model = translate(model, iVec3(position.x, position.y, -1.0f)); Changed this line, is that what you mean?
    – Aether
    Nov 9 at 3:04










  • @Patrick I'm starting to think is a view port error or something since, no matter what coordinates I enter, triangle will always be the same position with no texture.
    – Aether
    Nov 9 at 3:04
















What version of OpenGL are you running? Are you aware that as of OpenGL 3+ quads are deprecated?
– Patrick
Nov 9 at 2:27




What version of OpenGL are you running? Are you aware that as of OpenGL 3+ quads are deprecated?
– Patrick
Nov 9 at 2:27




1




1




@Patrick I just added Quads on the title because I´m trying to draw quads, but I´m Actually drawing 2 triangles next to each other, just updated the question with that code.
– Aether
Nov 9 at 2:33




@Patrick I just added Quads on the title because I´m trying to draw quads, but I´m Actually drawing 2 triangles next to each other, just updated the question with that code.
– Aether
Nov 9 at 2:33












Could you try changing the z coordinates of the triangles to -1.0f instead of 0.0f. I believe the triangle is clipping since positive z is out of screen.
– Patrick
Nov 9 at 2:44




Could you try changing the z coordinates of the triangles to -1.0f instead of 0.0f. I believe the triangle is clipping since positive z is out of screen.
– Patrick
Nov 9 at 2:44












@Patrick model = translate(model, iVec3(position.x, position.y, -1.0f)); Changed this line, is that what you mean?
– Aether
Nov 9 at 3:04




@Patrick model = translate(model, iVec3(position.x, position.y, -1.0f)); Changed this line, is that what you mean?
– Aether
Nov 9 at 3:04












@Patrick I'm starting to think is a view port error or something since, no matter what coordinates I enter, triangle will always be the same position with no texture.
– Aether
Nov 9 at 3:04




@Patrick I'm starting to think is a view port error or something since, no matter what coordinates I enter, triangle will always be the same position with no texture.
– Aether
Nov 9 at 3:04












1 Answer
1






active

oldest

votes

















up vote
4
down vote



accepted










You'r shader doesn't even compile. When you declare the matrix uniforms, then you use the names model2D, view2D and projection2D:



uniform mat4 view2D;
uniform mat4 model2D;
uniform mat4 projection2D;


But when you use the matrices, then you use the names view, model and projection:



gl_Position = projection * view * model * vec4(vertex.xy, 0.0, 1.0);




I recommend to check if the shader objects compiled successfully and if the program object link successfully.



If the compiling of a shader succeeded can be checked by glGetShaderiv and the parameter GL_COMPILE_STATUS.



e.g.



GLuint shaderObj = .... ;
glCompileShader( shaderObj );

GLint status = GL_TRUE;
glGetShaderiv( shaderObj, GL_COMPILE_STATUS, &status );
if ( status == GL_FALSE )
{
GLint logLen;
glGetShaderiv( shaderObj, GL_INFO_LOG_LENGTH, &logLen );
std::vector< char >log( logLen );
GLsizei written;
glGetShaderInfoLog( shaderObj, logLen, &written, log.data() );
std::cout << "compile error:" << std::endl << log.data() << std::endl;
}


If the linking of a program was successful can be checked by glGetProgramiv and the parameter GL_LINK_STATUS.



e.g.



GLuint progObj = ....;
glLinkProgram( progObj );

GLint status = GL_TRUE;
glGetProgramiv( progObj, GL_LINK_STATUS, &status );
if ( status == GL_FALSE )
{
GLint logLen;
glGetProgramiv( progObj, GL_INFO_LOG_LENGTH, &logLen );
std::vector< char >log( logLen );
GLsizei written;
glGetProgramInfoLog( progObj, logLen, &written, log.data() );
std::cout << "link error:" << std::endl << log.data() << std::endl;
}





share|improve this answer























  • got the following error, link error: Vertex info ----------- (0) : error C5145: must write to gl_Position.
    – Aether
    Nov 9 at 21:39












  • Just Updated the code with the Resources.cpp but I think there is no error while loading the shader.
    – Aether
    Nov 9 at 21:41










  • @MarceloColonia Ther is a typo in your code: mode2Dl instead of model2D
    – Rabbid76
    Nov 9 at 21:50












  • sorry that typo is because I manually wrote the update instead of copying it, the original code is correct.
    – Aether
    Nov 9 at 21:53










  • @MarceloColonia You got a link error, possibly you swapped the vertex and the fragment shader or you didn't proper load the shaders form the file and the source code strings are empty.
    – Rabbid76
    Nov 9 at 21:56













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53218925%2fopengl-ignores-quads-and-makes-them-triangles%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote



accepted










You'r shader doesn't even compile. When you declare the matrix uniforms, then you use the names model2D, view2D and projection2D:



uniform mat4 view2D;
uniform mat4 model2D;
uniform mat4 projection2D;


But when you use the matrices, then you use the names view, model and projection:



gl_Position = projection * view * model * vec4(vertex.xy, 0.0, 1.0);




I recommend to check if the shader objects compiled successfully and if the program object link successfully.



If the compiling of a shader succeeded can be checked by glGetShaderiv and the parameter GL_COMPILE_STATUS.



e.g.



GLuint shaderObj = .... ;
glCompileShader( shaderObj );

GLint status = GL_TRUE;
glGetShaderiv( shaderObj, GL_COMPILE_STATUS, &status );
if ( status == GL_FALSE )
{
GLint logLen;
glGetShaderiv( shaderObj, GL_INFO_LOG_LENGTH, &logLen );
std::vector< char >log( logLen );
GLsizei written;
glGetShaderInfoLog( shaderObj, logLen, &written, log.data() );
std::cout << "compile error:" << std::endl << log.data() << std::endl;
}


If the linking of a program was successful can be checked by glGetProgramiv and the parameter GL_LINK_STATUS.



e.g.



GLuint progObj = ....;
glLinkProgram( progObj );

GLint status = GL_TRUE;
glGetProgramiv( progObj, GL_LINK_STATUS, &status );
if ( status == GL_FALSE )
{
GLint logLen;
glGetProgramiv( progObj, GL_INFO_LOG_LENGTH, &logLen );
std::vector< char >log( logLen );
GLsizei written;
glGetProgramInfoLog( progObj, logLen, &written, log.data() );
std::cout << "link error:" << std::endl << log.data() << std::endl;
}





share|improve this answer























  • got the following error, link error: Vertex info ----------- (0) : error C5145: must write to gl_Position.
    – Aether
    Nov 9 at 21:39












  • Just Updated the code with the Resources.cpp but I think there is no error while loading the shader.
    – Aether
    Nov 9 at 21:41










  • @MarceloColonia Ther is a typo in your code: mode2Dl instead of model2D
    – Rabbid76
    Nov 9 at 21:50












  • sorry that typo is because I manually wrote the update instead of copying it, the original code is correct.
    – Aether
    Nov 9 at 21:53










  • @MarceloColonia You got a link error, possibly you swapped the vertex and the fragment shader or you didn't proper load the shaders form the file and the source code strings are empty.
    – Rabbid76
    Nov 9 at 21:56

















up vote
4
down vote



accepted










You'r shader doesn't even compile. When you declare the matrix uniforms, then you use the names model2D, view2D and projection2D:



uniform mat4 view2D;
uniform mat4 model2D;
uniform mat4 projection2D;


But when you use the matrices, then you use the names view, model and projection:



gl_Position = projection * view * model * vec4(vertex.xy, 0.0, 1.0);




I recommend to check if the shader objects compiled successfully and if the program object link successfully.



If the compiling of a shader succeeded can be checked by glGetShaderiv and the parameter GL_COMPILE_STATUS.



e.g.



GLuint shaderObj = .... ;
glCompileShader( shaderObj );

GLint status = GL_TRUE;
glGetShaderiv( shaderObj, GL_COMPILE_STATUS, &status );
if ( status == GL_FALSE )
{
GLint logLen;
glGetShaderiv( shaderObj, GL_INFO_LOG_LENGTH, &logLen );
std::vector< char >log( logLen );
GLsizei written;
glGetShaderInfoLog( shaderObj, logLen, &written, log.data() );
std::cout << "compile error:" << std::endl << log.data() << std::endl;
}


If the linking of a program was successful can be checked by glGetProgramiv and the parameter GL_LINK_STATUS.



e.g.



GLuint progObj = ....;
glLinkProgram( progObj );

GLint status = GL_TRUE;
glGetProgramiv( progObj, GL_LINK_STATUS, &status );
if ( status == GL_FALSE )
{
GLint logLen;
glGetProgramiv( progObj, GL_INFO_LOG_LENGTH, &logLen );
std::vector< char >log( logLen );
GLsizei written;
glGetProgramInfoLog( progObj, logLen, &written, log.data() );
std::cout << "link error:" << std::endl << log.data() << std::endl;
}





share|improve this answer























  • got the following error, link error: Vertex info ----------- (0) : error C5145: must write to gl_Position.
    – Aether
    Nov 9 at 21:39












  • Just Updated the code with the Resources.cpp but I think there is no error while loading the shader.
    – Aether
    Nov 9 at 21:41










  • @MarceloColonia Ther is a typo in your code: mode2Dl instead of model2D
    – Rabbid76
    Nov 9 at 21:50












  • sorry that typo is because I manually wrote the update instead of copying it, the original code is correct.
    – Aether
    Nov 9 at 21:53










  • @MarceloColonia You got a link error, possibly you swapped the vertex and the fragment shader or you didn't proper load the shaders form the file and the source code strings are empty.
    – Rabbid76
    Nov 9 at 21:56















up vote
4
down vote



accepted







up vote
4
down vote



accepted






You'r shader doesn't even compile. When you declare the matrix uniforms, then you use the names model2D, view2D and projection2D:



uniform mat4 view2D;
uniform mat4 model2D;
uniform mat4 projection2D;


But when you use the matrices, then you use the names view, model and projection:



gl_Position = projection * view * model * vec4(vertex.xy, 0.0, 1.0);




I recommend to check if the shader objects compiled successfully and if the program object link successfully.



If the compiling of a shader succeeded can be checked by glGetShaderiv and the parameter GL_COMPILE_STATUS.



e.g.



GLuint shaderObj = .... ;
glCompileShader( shaderObj );

GLint status = GL_TRUE;
glGetShaderiv( shaderObj, GL_COMPILE_STATUS, &status );
if ( status == GL_FALSE )
{
GLint logLen;
glGetShaderiv( shaderObj, GL_INFO_LOG_LENGTH, &logLen );
std::vector< char >log( logLen );
GLsizei written;
glGetShaderInfoLog( shaderObj, logLen, &written, log.data() );
std::cout << "compile error:" << std::endl << log.data() << std::endl;
}


If the linking of a program was successful can be checked by glGetProgramiv and the parameter GL_LINK_STATUS.



e.g.



GLuint progObj = ....;
glLinkProgram( progObj );

GLint status = GL_TRUE;
glGetProgramiv( progObj, GL_LINK_STATUS, &status );
if ( status == GL_FALSE )
{
GLint logLen;
glGetProgramiv( progObj, GL_INFO_LOG_LENGTH, &logLen );
std::vector< char >log( logLen );
GLsizei written;
glGetProgramInfoLog( progObj, logLen, &written, log.data() );
std::cout << "link error:" << std::endl << log.data() << std::endl;
}





share|improve this answer














You'r shader doesn't even compile. When you declare the matrix uniforms, then you use the names model2D, view2D and projection2D:



uniform mat4 view2D;
uniform mat4 model2D;
uniform mat4 projection2D;


But when you use the matrices, then you use the names view, model and projection:



gl_Position = projection * view * model * vec4(vertex.xy, 0.0, 1.0);




I recommend to check if the shader objects compiled successfully and if the program object link successfully.



If the compiling of a shader succeeded can be checked by glGetShaderiv and the parameter GL_COMPILE_STATUS.



e.g.



GLuint shaderObj = .... ;
glCompileShader( shaderObj );

GLint status = GL_TRUE;
glGetShaderiv( shaderObj, GL_COMPILE_STATUS, &status );
if ( status == GL_FALSE )
{
GLint logLen;
glGetShaderiv( shaderObj, GL_INFO_LOG_LENGTH, &logLen );
std::vector< char >log( logLen );
GLsizei written;
glGetShaderInfoLog( shaderObj, logLen, &written, log.data() );
std::cout << "compile error:" << std::endl << log.data() << std::endl;
}


If the linking of a program was successful can be checked by glGetProgramiv and the parameter GL_LINK_STATUS.



e.g.



GLuint progObj = ....;
glLinkProgram( progObj );

GLint status = GL_TRUE;
glGetProgramiv( progObj, GL_LINK_STATUS, &status );
if ( status == GL_FALSE )
{
GLint logLen;
glGetProgramiv( progObj, GL_INFO_LOG_LENGTH, &logLen );
std::vector< char >log( logLen );
GLsizei written;
glGetProgramInfoLog( progObj, logLen, &written, log.data() );
std::cout << "link error:" << std::endl << log.data() << std::endl;
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 9 at 6:24

























answered Nov 9 at 6:16









Rabbid76

30.3k112842




30.3k112842












  • got the following error, link error: Vertex info ----------- (0) : error C5145: must write to gl_Position.
    – Aether
    Nov 9 at 21:39












  • Just Updated the code with the Resources.cpp but I think there is no error while loading the shader.
    – Aether
    Nov 9 at 21:41










  • @MarceloColonia Ther is a typo in your code: mode2Dl instead of model2D
    – Rabbid76
    Nov 9 at 21:50












  • sorry that typo is because I manually wrote the update instead of copying it, the original code is correct.
    – Aether
    Nov 9 at 21:53










  • @MarceloColonia You got a link error, possibly you swapped the vertex and the fragment shader or you didn't proper load the shaders form the file and the source code strings are empty.
    – Rabbid76
    Nov 9 at 21:56




















  • got the following error, link error: Vertex info ----------- (0) : error C5145: must write to gl_Position.
    – Aether
    Nov 9 at 21:39












  • Just Updated the code with the Resources.cpp but I think there is no error while loading the shader.
    – Aether
    Nov 9 at 21:41










  • @MarceloColonia Ther is a typo in your code: mode2Dl instead of model2D
    – Rabbid76
    Nov 9 at 21:50












  • sorry that typo is because I manually wrote the update instead of copying it, the original code is correct.
    – Aether
    Nov 9 at 21:53










  • @MarceloColonia You got a link error, possibly you swapped the vertex and the fragment shader or you didn't proper load the shaders form the file and the source code strings are empty.
    – Rabbid76
    Nov 9 at 21:56


















got the following error, link error: Vertex info ----------- (0) : error C5145: must write to gl_Position.
– Aether
Nov 9 at 21:39






got the following error, link error: Vertex info ----------- (0) : error C5145: must write to gl_Position.
– Aether
Nov 9 at 21:39














Just Updated the code with the Resources.cpp but I think there is no error while loading the shader.
– Aether
Nov 9 at 21:41




Just Updated the code with the Resources.cpp but I think there is no error while loading the shader.
– Aether
Nov 9 at 21:41












@MarceloColonia Ther is a typo in your code: mode2Dl instead of model2D
– Rabbid76
Nov 9 at 21:50






@MarceloColonia Ther is a typo in your code: mode2Dl instead of model2D
– Rabbid76
Nov 9 at 21:50














sorry that typo is because I manually wrote the update instead of copying it, the original code is correct.
– Aether
Nov 9 at 21:53




sorry that typo is because I manually wrote the update instead of copying it, the original code is correct.
– Aether
Nov 9 at 21:53












@MarceloColonia You got a link error, possibly you swapped the vertex and the fragment shader or you didn't proper load the shaders form the file and the source code strings are empty.
– Rabbid76
Nov 9 at 21:56






@MarceloColonia You got a link error, possibly you swapped the vertex and the fragment shader or you didn't proper load the shaders form the file and the source code strings are empty.
– Rabbid76
Nov 9 at 21:56




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53218925%2fopengl-ignores-quads-and-makes-them-triangles%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff