Jump to content

  • Log In with Google      Sign In   
  • Create Account

Prot

Member Since 05 Jul 2013
Offline Last Active Jul 27 2016 02:30 AM

Posts I've Made

In Topic: Triangle rendered white only.

15 February 2016 - 03:41 AM

if you change it to the above code it should have the right size even if you change your vector.

 

As for the problem of the colours does hard coding a colour into your shader change it to that colour? So something like

out_color = vec4(1.0, 0.0, 0.0, 1.0);

that should change the triangle to red. I know you don't want just a red one but this will eliminate the shader as the problem

 

 

Actually it does not change anything.

 

I have to take the time to try all the other suggestions.


In Topic: Triangle rendered white only.

12 February 2016 - 07:02 PM

I do get "GL_INVALID_ENUM" right after glGenVertexArrays(1,&vao);


In Topic: Triangle rendered white only.

12 February 2016 - 11:32 AM

Nopes, unfortunately this didn't change the behaviour. 

 

I don't even know how to approach debugging shader output, any hints? Also what should be the Item Type of a glsl-shader under Visual Studio 2013? Currently my shader files are set to Custom Build Tool.


In Topic: Triangle rendered white only.

09 February 2016 - 04:47 AM

But it does seem to compile the Shaders, without printing any faling information to the console, fyi here the Shader_Manager-class:

#include "Shader_Manager.h"
#include <iostream>
#include <fstream>
#include <vector>

std::map<std::string, GLuint> Shader_Manager::programs;



Shader_Manager::Shader_Manager(void) {}

Shader_Manager::~Shader_Manager(void) 
{
	std::map<std::string, GLuint>::iterator i;
	for (i = programs.begin(); i != programs.end(); ++i)
	{
		GLuint pr = i->second;
		glDeleteProgram(pr);
	}
	programs.clear();
}

const GLuint Shader_Manager::GetShader(const std::string & shaderName)
{
	return programs.at(shaderName);
}

//reads and returns the contents of a file
std::string Shader_Manager::ReadShader(const std::string& filename)
{
	std::string shaderCode;
	std::ifstream file(filename,std::ios::in);

	if (!file.good())
	{
		std::cout << "Can't read file" << filename.c_str() << std::endl;
		std::terminate();
	}

	file.seekg(0,std::ios::end);
	shaderCode.resize((unsigned int)file.tellg());
	file.seekg(0,std::ios::beg);
	file.read(&shaderCode[0],shaderCode.size());
	file.close();
	return shaderCode;
}

//creates and compiles a shader (vertex or fragment)
GLuint Shader_Manager::CreateShader(GLenum shaderType,const std::string& source,const std::string& shaderName)
{
	int compile_result = 0;

	GLuint shader = glCreateShader(shaderType);
	const char *shader_code_ptr = source.c_str();
	const int shader_code_size = source.size();

	glShaderSource(shader,1,&shader_code_ptr,&shader_code_size);
	glCompileShader(shader);
	glGetShaderiv(shader,GL_COMPILE_STATUS,&compile_result);

	//check for errors
	if (compile_result == GL_FALSE)
	{
		int info_log_length = 0;
		glGetShaderiv(shader,GL_INFO_LOG_LENGTH,&info_log_length);
		std::vector<char> shader_log(info_log_length);
		glGetShaderInfoLog(shader,info_log_length,NULL,&shader_log[0]);
		std::cout << "ERROR compiling shader: " << shaderName.c_str() << std::endl << &shader_log[0] << std::endl;
		return 0;
	}

	return shader;
}

//uses ReadShader to extract the shader contents and  to create both shaders and load them into the program which is returned to be used in rendering loop
void Shader_Manager::CreateProgramm(const std::string& shaderName,
									  const std::string& vertexShaderFilename,
									  const std::string& fragmentShaderFilename)
{
	//read the shader files and save the code
	std::string vertex_shader_code = ReadShader(vertexShaderFilename);
	std::string fragment_shader_code = ReadShader(fragmentShaderFilename);

	GLuint vertex_shader = CreateShader(GL_VERTEX_SHADER,vertex_shader_code,"vertex shader");
	GLuint fragment_shader = CreateShader(GL_FRAGMENT_SHADER,fragment_shader_code,"fragment shader");

	int link_result = 0;
	//create the program handle, attach the shaders and link it
	GLuint program = glCreateProgram();
	glAttachShader(program,vertex_shader);
	glAttachShader(program,fragment_shader);

	glLinkProgram(program);
	glGetProgramiv(program,GL_LINK_STATUS,&link_result);
	//check for link errors
	if (link_result == GL_FALSE)
	{
		int info_log_length = 0;
		glGetProgramiv(program,GL_INFO_LOG_LENGTH,&info_log_length);
		std::vector<char> program_log(info_log_length);
		glGetProgramInfoLog(program,info_log_length,NULL,&program_log[0]);
		std::cout << "Shader Loader: LINK ERROR" << std::endl << &program_log[0] << std::endl;
		return;
	}

	programs[shaderName] = program;
}

I was assuming that if the shaders are failing to compile I would have seen it in the console.


In Topic: Please help me fix my Mono class.

31 August 2015 - 08:58 AM

Ok I read it and also did understand it. One thing I have to ask, though.

It is pretty clear that in the example posted by phil_t Box contains all variables a Rectangle (XNA) also contains. But what is the Box's velocity supposed to be? Is it the offset between the last and the new position? This I do not fully understand.


PARTNERS