Jump to content

  • Log In with Google      Sign In   
  • Create Account

CoffeeandCode

Member Since 18 Apr 2013
Offline Last Active Dec 16 2014 06:23 AM

Topics I've Started

NEED HELP! Window displays nothing :/ OpenGL & SDL

18 April 2013 - 12:19 AM

Hello.

I have been working on a game engine for a couple of days now and I've had it rendering a colourful cube and playing sounds in OGG format, but, after refractoring my code-base to make things easier it no longer displays the cube! (This happened when I put the shader program and methods into a seperate class)

What could be the problem?

 

OpenGL/SDL2 context class:

class RenderContext{
	public:
		RenderContext();
		~RenderContext();

		void draw();

		//void swapbuffers();

		int16_t good;

		ShaderProgram *program;

	private:
		WindowSDL *window;
		FontLoading *fonts;
};

 

 

 

ShaderProgram blass:

class ShaderProgram{
	public:	
                ShaderProgram(){
		}

		ShaderProgram(const char *vsPath, const char *fsPath){
			int32_t compileStat, linkStat;
			uint32_t vertexS = glCreateShader(GL_VERTEX_SHADER);
			uint32_t fragS = glCreateShader(GL_FRAGMENT_SHADER);

			string vsSource = LoadFile(vsPath);
			string fsSource = LoadFile(fsPath);
			const char *source = vsSource.c_str();
			glShaderSource(vertexS, 1, &source, NULL);
			source = fsSource.c_str();
			glShaderSource(fragS, 1, &source, NULL);

			glCompileShader(vertexS);
			glGetShaderiv(vertexS, GL_COMPILE_STATUS, &compileStat);
			if(compileStat == 0){
				char BUFFER[256];
				glGetShaderInfoLog(vertexS, sizeof(BUFFER), NULL, BUFFER);
				cerr << "-!- Error compiling vertex shader: " << BUFFER << endl;
				good = false;
				return;
			}

			glCompileShader(fragS);
			glGetShaderiv(fragS, GL_COMPILE_STATUS, &compileStat);
			if(compileStat == 0){
				char BUFFER[256];
				glGetShaderInfoLog(fragS, sizeof(BUFFER), NULL, BUFFER);
				cerr << "-!- Error compiling fragment shader: " << BUFFER << endl;
				good = false;
				return;
			}

			program = glCreateProgram();
			glAttachShader(program, vertexS);
			glAttachShader(program, fragS);

			glLinkProgram(program);
			glGetProgramiv(program, GL_LINK_STATUS, &linkStat);
			if(!linkStat){
				cerr << "-!- Error linking program." << endl;
				good = false;
				return;
			}

			good = true;
		}

		void getUniform(uint32_t &location, const char *uniformName){
			location = glGetUniformLocation(program, uniformName);
			assert(location != 0xFFFFFFFF);
		}

		void bind(){
			glUseProgram(program);
		}

		void unbind(){
			glUseProgram(0);
		}

		~ShaderProgram(){
			glDeleteProgram(program);
			glUseProgram(0);
		}

		bool good;
		uint32_t program;
};

 


Included a screenshot of output now and a screenshot of output then.

Thanks.

 

Attached File  Screenshot from 2013-04-16 23:12:34.png   324.05KB   209 downloads

Attached File  Screenshot from 2013-04-18 18:12:26.png   298.36KB   184 downloads


PARTNERS