Exemplo n.º 1
0
/*
    Reads in and compiles shader objects
 */
void glutWidget::makeShaders()
{
    m_program = glCreateProgram();
	
    char *shadercode = readShader("shaders/vertexshader.vert");	//reads shader code (you can edit shader code with a text editor)
    m_vertexsh = glCreateShader(GL_VERTEX_SHADER_ARB);
    glShaderSource(m_vertexsh, 1, (const GLcharARB **)&shadercode,NULL);
    delete[] shadercode;
    glCompileShader(m_vertexsh);    //compiles shader
    printInfoLog(m_vertexsh);       //prints errors during shader compilation
    
    
    shadercode = readShader("shaders/fragmentshader.frag");     //reads shader code (you can edit shader code with a text editor)
    m_fragmentsh = glCreateShader(GL_FRAGMENT_SHADER_ARB);
    glShaderSource(m_fragmentsh, 1, (const GLcharARB **)&shadercode,NULL);
    delete[] shadercode;
    glCompileShader(m_fragmentsh);  //compiles shader
    printInfoLog(m_fragmentsh);     //prints errors during shader compilation

    glAttachShader(m_program,m_vertexsh);
    glAttachShader(m_program,m_fragmentsh);

    glLinkProgram(m_program);   //compiles fragment and vertex shader into a shader program
    printInfoLog(m_program);    //prints errors during program compilation
}
GL_Controller::Shader::Shader(const char* vsfn, const char* fsfn)
{
    vertexShader   = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
    fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);

    std::string vertexShaderSource   = ReadFile(vsfn);
    std::string fragmentShaderSource = ReadFile(fsfn);

    const char* v = vertexShaderSource.c_str();
    const char* f = fragmentShaderSource.c_str();

    glShaderSourceARB(vertexShader, 1, &v, NULL);
    glShaderSourceARB(fragmentShader, 1, &f, NULL);

    glCompileShaderARB(vertexShader);
    glCompileShaderARB(fragmentShader);

    printInfoLog(vertexShader);
    printInfoLog(fragmentShader);

    shaderProgram = glCreateProgramObjectARB();
    glAttachObjectARB(shaderProgram, vertexShader);
    glAttachObjectARB(shaderProgram, fragmentShader);

    glLinkProgramARB(shaderProgram);
    printInfoLog(shaderProgram);

    glUseProgramObjectARB(shaderProgram);
}
Exemplo n.º 3
0
shader::~shader()
{
	//std::cerr << "deleting shaders" << std::endl;
	// delete fragment and vertex shader and check status
	glDeleteObjectARB(vertexshader);
	printInfoLog(vertexshader);
	glDeleteObjectARB(fragmentshader);
	printInfoLog(fragmentshader);
}
Exemplo n.º 4
0
bool Shader::SetShaderFile(char* sVSFileName, char* sFSFileName)
{
	if (glIsProgram(m_Program))
	{
		CleanUp();
	}
	if (!ReadVertextShader(sVSFileName) || !ReadFragmentShader(sFSFileName))
	{
		return false;
	}
	GLint vertCompiled, fragCompiled;			//状态值
	GLint linked;
	//创建shader对象
	m_Vert = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
	m_Frag = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);

	const GLcharARB *vv = m_VertexShader;
	const GLcharARB *ff = m_FragmentShader;
	//添加shader
	glShaderSourceARB(m_Vert,1,&vv,NULL);
	glShaderSourceARB(m_Frag,1,&ff,NULL);

	//编译shader
	glCompileShaderARB(m_Vert);
	printOpenGLError(); //检查OpenGL错误
	//glGetObjectParameterivARB(m_Vert, GL_OBJECT_COMPILE_STATUS_ARB, &vertCompiled);
	glGetShaderiv(m_Vert, GL_COMPILE_STATUS, &vertCompiled);
	printInfoLog(m_Vert);
	glCompileShaderARB(m_Frag);
	printOpenGLError(); //检查OpenGL错误
	//glGetObjectParameterivARB(m_Frag, GL_OBJECT_COMPILE_STATUS_ARB, &fragCompiled);
	glGetShaderiv(m_Frag, GL_COMPILE_STATUS, &fragCompiled);
	printInfoLog(m_Frag); 

	if (!vertCompiled || !fragCompiled)
		return false;

	//创建程序对象
	m_Program = glCreateProgramObjectARB();

	//绑定shader到程序对象
	glAttachObjectARB(m_Program,m_Vert);
	glAttachObjectARB(m_Program,m_Frag);	

	//链接程序
	glLinkProgramARB(m_Program);
	printOpenGLError(); //检查OpenGL错误
	//glGetObjectParameterivARB(m_Program, GL_OBJECT_COMPILE_STATUS_ARB, &linked);
	glGetProgramiv(m_Program, GL_LINK_STATUS, &linked);  
	printInfoLog(m_Program);

	if (!linked)
		return false; 
	UseShader(true);				
	return true;
}
Exemplo n.º 5
0
/**
    Returns UR_OK/UR_THROW.
*/
static int createShader( UThread* ut, Shader* sh,
                         const char* vert, const char* frag )
{
    GLint ok;
    GLuint vertexObj;
    GLuint fragmentObj;


    sh->program = glCreateProgram();
    vertexObj   = glCreateShader( GL_VERTEX_SHADER );
    fragmentObj = glCreateShader( GL_FRAGMENT_SHADER );


    glShaderSource( vertexObj, 1, (const GLchar**) &vert, 0 );
    glCompileShader( vertexObj );
    glGetShaderiv( vertexObj, GL_COMPILE_STATUS, &ok );
    if( ! ok )
        return printInfoLog( ut, vertexObj, 0 );


    glShaderSource( fragmentObj, 1, (const GLchar**) &frag, 0 );
    glCompileShader( fragmentObj );
    glGetShaderiv( fragmentObj, GL_COMPILE_STATUS, &ok );
    if( ! ok )
        return printInfoLog( ut, fragmentObj, 0 );


    glAttachShader( sh->program, vertexObj );
    glAttachShader( sh->program, fragmentObj );

#ifndef __ANDROID__
    // These will actually go away when the program is deleted.
    glDeleteShader( vertexObj );
    glDeleteShader( fragmentObj );
#endif

#if 0
    glGetShaderiv( vertexObj, GL_DELETE_STATUS, &ok );
    fprintf( stderr, "KR vertex delete %d\n", ok );
    glGetShaderiv( fragmentObj, GL_DELETE_STATUS, &ok );
    fprintf( stderr, "KR fragment delete %d\n", ok );
#endif

    /*
    glBindAttribLocation( sh->program, 0, "bg_vertex" );
    glBindAttribLocation( sh->program, 1, "bg_color" );
    glBindAttribLocation( sh->program, 2, "bg_normal" );
    */
    
    glLinkProgram( sh->program );
    glGetProgramiv( sh->program, GL_LINK_STATUS, &ok );
    if( ! ok )
        return printInfoLog( ut, sh->program, 1 );

    return UR_OK;
}
Exemplo n.º 6
0
bool CreateShader(char *VShader, char *PShader, GLhandleARB *glContext) {

   printf("Loading vertex shader:%s\n", VShader) ;
   printf("Loading fragment shader:%s\n", PShader) ;   
   
   char error[4096];
   int result;
   GLhandleARB glVertexShader;
   GLhandleARB glPixelShader;

   // Create the program object.
   *glContext = glCreateProgramObjectARB();

   // Load the vertex shader.
   char *ShaderCode = loadShader(VShader);
   if(!ShaderCode) return false;
   glVertexShader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
   glShaderSourceARB(glVertexShader, 1, (const char**)&ShaderCode, NULL);
   glCompileShaderARB(glVertexShader);
   printInfoLog(glVertexShader) ;
   glGetObjectParameterivARB(glVertexShader, GL_OBJECT_COMPILE_STATUS_ARB, &result);
   glAttachObjectARB(*glContext, glVertexShader);
   delete[] ShaderCode;
   ShaderCode = NULL;

   // Load the pixel shader.
   ShaderCode = loadShader(PShader);
   if(!ShaderCode) return false;
   glPixelShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
   glShaderSourceARB(glPixelShader, 1, (const char**)&ShaderCode, NULL);
   glCompileShaderARB(glPixelShader);
   printInfoLog(glPixelShader) ;
   glGetObjectParameterivARB(glPixelShader, GL_OBJECT_COMPILE_STATUS_ARB, &result);
   glAttachObjectARB(*glContext, glPixelShader);
   delete[] ShaderCode;
   ShaderCode = NULL;

   // Link our shaders.
   glLinkProgramARB(*glContext);
   glGetObjectParameterivARB(*glContext, GL_OBJECT_LINK_STATUS_ARB, &result);

   if(!result) {
       glGetInfoLogARB(*glContext, sizeof(error), NULL, error);
       fprintf(stderr, "Error linking shaders...") ;
       return false;
   }

   glDeleteObjectARB(glVertexShader);
   glDeleteObjectARB(glPixelShader);
   return true;
}
Exemplo n.º 7
0
Arquivo: Shader.cpp Projeto: NCCA/NGL
bool Shader::compile() noexcept
{
  if (m_source.empty() )
  {
    msg->addError("Warning no shader source loaded");
    return false;
  }

  glCompileShader(m_shaderHandle);

  GLint compileStatus = 0;
  glGetShaderiv(m_shaderHandle, GL_COMPILE_STATUS,&compileStatus);
  m_compiled=static_cast<bool>(compileStatus);
  if(m_debugState==true)
  {
    msg->addMessage(fmt::format("Compiling Shader {0}",m_name));
    if( compileStatus == GL_FALSE)
    {
      msg->addError("Shader compile failed or had warnings ");
      printInfoLog(m_shaderHandle);
      if(m_errorExit==ErrorExit::ON)
        exit(EXIT_FAILURE);
    }
  }
  return m_compiled;
}
Exemplo n.º 8
0
Arquivo: Shader.cpp Projeto: NCCA/NGL
void Shader::load(const std::string &_name ) noexcept
{
  // see if we already have some source attached
  if(!m_source.empty())
  {
    msg->addWarning("deleting existing source code\n");
    m_source.clear();
  }
  std::ifstream shaderSource(_name.data());
  if (!shaderSource.is_open())
  {
   msg->addError(fmt::format("File not found {0}",_name.data()));
   exit(EXIT_FAILURE);
  }
  // now read in the data
  m_source =  std::string((std::istreambuf_iterator<char>(shaderSource)), std::istreambuf_iterator<char>());
  shaderSource.close();
  // glShaderSource needs null terminated const char *
  m_source+='\0';
  m_originalSource=m_source;
  const char* data=m_source.c_str();
  glShaderSource(m_shaderHandle , 1, &data,nullptr);
  m_compiled=false;

  if (m_debugState == true)
  {
    printInfoLog(m_shaderHandle);
  }
}
Exemplo n.º 9
0
void Shader::load( std::string _name ) noexcept
{
  // see if we already have some source attached
  if(m_source.empty())
  {
    std::cerr<<"deleting existing source code\n";
    m_source.clear();
  }
  std::ifstream shaderSource(_name.c_str());
  if (!shaderSource.is_open())
  {
   std::cerr<<"File not found "<<_name.c_str()<<"\n";
   //exit(EXIT_FAILURE);
  }
  // now read in the data
  m_source =  std::string((std::istreambuf_iterator<char>(shaderSource)), std::istreambuf_iterator<char>());
  shaderSource.close();
  // glShaderSource needs null terminated const char *
  m_source+='\0';
  const char* data=m_source.c_str();
  glShaderSource(m_shaderHandle , 1, &data,NULL);
  m_compiled=false;

  if (m_debugState == true)
  {
    printInfoLog(m_shaderHandle);
  }
}
Exemplo n.º 10
0
shader::shader(char* vert, char* frag)
{
	//std::cerr << "creating shaders : " << vert << ", " << frag << std::endl;
	this->vert=vert;
	this->frag=frag;
	uniformIdx = 0;
	n_tex = 0;

	// create shader objects
	shaderobj = glCreateProgramObjectARB();
	vertexshader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
	fragmentshader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);

	// get source code for fragment and vertex shader
	char * source;
	source = GetSource(vert);
	glShaderSourceARB(vertexshader, 1, (const GLcharARB**)&source, NULL);

	source = GetSource(frag);
	glShaderSourceARB(fragmentshader, 1, (const GLcharARB**)&source, NULL);

	// compile the fragment and vertex shader
	glCompileShader(vertexshader);
	glCompileShader(fragmentshader);

	// attach shaders to shader obj
	glAttachObjectARB(shaderobj, vertexshader);
	glAttachObjectARB(shaderobj, fragmentshader);

	// link the shader obj and check status
	glLinkProgramARB(shaderobj);
	printInfoLog(shaderobj);
}
Exemplo n.º 11
0
Arquivo: Shader.cpp Projeto: FMX/CGAL
//--------------------------------------------------------------------------------
bool Shader::loadSources(const char* vsrc, const char* fsrc)
{
    bool allIsOk = false;

    mProgramID = glCreateProgram();

    std::string defineStr = "";
    for(DefineMap::iterator it = mDefines.begin() ; it!=mDefines.end() ; ++it)
    {
      defineStr += "#define " + it->first + " " + it->second + "\n";
    }

    if(vsrc)
    {
        GLuint shaderID = glCreateShader(GL_VERTEX_SHADER);

        std::string source = defineStr + std::string(vsrc);
        const GLchar * arbSource = source.c_str();

        glShaderSource(shaderID, 1, (const GLchar **)&arbSource, 0);
        glCompileShader(shaderID);

        int compiled;
        glGetShaderiv(shaderID,GL_COMPILE_STATUS,&compiled);
        allIsOk = allIsOk && compiled;
        //printInfoLog(shaderID);

        glAttachShader(mProgramID, shaderID);
    }

    if(fsrc)
    {
        GLuint shaderID = glCreateShader(GL_FRAGMENT_SHADER);

        std::string source = defineStr + std::string(fsrc);
        const GLchar * arbSource = source.c_str();

        glShaderSource(shaderID, 1, (const GLchar **)&arbSource, 0);
        glCompileShader(shaderID);

        int compiled;
        glGetShaderiv(shaderID,GL_COMPILE_STATUS,&compiled);
        allIsOk = allIsOk && compiled;
        //printInfoLog(shaderID);

        glAttachShader(mProgramID, shaderID);
    }

    glLinkProgram(mProgramID);

    int isLinked;
    glGetProgramiv(mProgramID, GL_LINK_STATUS, &isLinked);
    allIsOk = allIsOk && isLinked;
    mIsValid = isLinked == GL_TRUE;
    printInfoLog(mProgramID);

    return allIsOk;
}
Exemplo n.º 12
0
void setShaders()
{
    static int inited = 0;
    char *vs = NULL,*fs = NULL;
    GLhandleARB v,f,f2,p;
    if (! inited)
    {

        v = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
        f = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
        f2 = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
    }

    vs = textFileRead("myshader.vert");
    fs = textFileRead("myshader.frag");

    const char * vv = vs;
    const char * ff = fs;

    glShaderSourceARB(v, 1, &vv,NULL);
    glShaderSourceARB(f, 1, &ff,NULL);

    free(vs);
    free(fs);

    glCompileShaderARB(v);
    glCompileShaderARB(f);

    printInfoLog(v);
    printInfoLog(f);
    printInfoLog(f2);

    if (! inited)
    {
        p = glCreateProgramObjectARB();
    }
    glAttachObjectARB(p,v);
    glAttachObjectARB(p,f);

    glLinkProgramARB(p);
    printInfoLog(p);

    glUseProgramObjectARB(p);
}
Exemplo n.º 13
0
void MyGlWindow::loadShader( GLhandleARB& program, const char* vertexFile, const char* fragmentFile ){
	// initialize glew
	int glewError = glewInit();
	if( glewError ) printf("Error: %s\n", glewGetErrorString(glewError));

	// create shader program object and both a vertex and fragment object
	program		= glCreateProgramObjectARB();
	GLhandleARB	vertex		= glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
	GLhandleARB fragment	= glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);

	// read shaders into strings
	const char* vertexString = readShaderSource(vertexFile);
	const char* fragmentString = readShaderSource(fragmentFile);

	// give ogl the shader source string
	glShaderSourceARB(vertex, 1, &vertexString, NULL);
	glShaderSourceARB(fragment, 1, &fragmentString, NULL);

	// compile shaders
	glCompileShaderARB(vertex);
	printInfoLog(vertex);

	glCompileShaderARB(fragment);
	printInfoLog(fragment);

	// attach shaders to program object and link
	glAttachObjectARB(program, vertex);
	glAttachObjectARB(program, fragment);
	glLinkProgramARB(program);

	// display results
	GLint success;
	glGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &success);
	if( !success ) 
	{
		printf("%s and %s shader could not be linked!\n", vertexFile, fragmentFile );
		exit(-1); // bail out, display isn't going to happen at this point.
	}
	else
	{
		printf("%s and %s loaded and linked successfully.\n", vertexFile, fragmentFile );
	}
}
Exemplo n.º 14
0
//#define rglAssert(...)
rglShader_t * rglCreateShader(const char * vsrc, const char * fsrc)
{
  GLhandleARB vs, fs, prog;

  //printf("Compiling shader :\n%s", fsrc);
  
  vs = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
  rglAssert(glGetError() == GL_NO_ERROR);
	fs = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
  rglAssert(glGetError() == GL_NO_ERROR);

	glShaderSourceARB(vs, 1, &vsrc,NULL);
  rglAssert(glGetError() == GL_NO_ERROR);
	glShaderSourceARB(fs, 1, &fsrc,NULL);
  rglAssert(glGetError() == GL_NO_ERROR);
	glCompileShaderARB(vs);
  rglAssert(glGetError() == GL_NO_ERROR);
	glCompileShaderARB(fs);
  rglAssert(glGetError() == GL_NO_ERROR);
  printInfoLog(vs, vsrc);
  printInfoLog(fs, fsrc);
	prog = glCreateProgramObjectARB();
	glAttachObjectARB(prog, fs);
  rglAssert(glGetError() == GL_NO_ERROR);
	glAttachObjectARB(prog, vs);
  rglAssert(glGetError() == GL_NO_ERROR);

	glLinkProgramARB(prog);
  rglAssert(glGetError() == GL_NO_ERROR);

  rglShader_t * s = (rglShader_t *) malloc(sizeof(rglShader_t));
  s->vs = vs;
  s->fs = fs;
  s->prog = prog;
  //LOG("Creating shader %d %d %d\n", s->vs, s->fs, s->prog);
#ifdef RDP_DEBUG
  s->vsrc = strdup(vsrc);
  s->fsrc = strdup(fsrc);
#endif
  return s;
}
Exemplo n.º 15
0
int Shader::installShaders()
{
    GLhandleARB vs, fs;
    GLint       vertCompiled, fragCompiled;

	// Criar objectos
    vs = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
    fs = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);

    // Carregar strings
    glShaderSourceARB(vs, 1, (const GLcharARB**)&m_VertShdStr, NULL);
    glShaderSourceARB(fs, 1, (const GLcharARB**)&m_FragShdStr, NULL);

    glCompileShaderARB(vs);
    glGetObjectParameterivARB(vs, GL_OBJECT_COMPILE_STATUS_ARB, &vertCompiled);
    if (!vertCompiled)
	{
//		console->printfAndRender(1.0f, 0.0f, 0.0f, "Error compiling vertex shader '%s':", strrchr(m_FileName, '\\') + 1);
		printInfoLog(vs);
		return false;
	}

    glCompileShaderARB(fs);
    glGetObjectParameterivARB(fs, GL_OBJECT_COMPILE_STATUS_ARB, &fragCompiled);
	if (!fragCompiled)
	{
//		console->printfAndRender(1.0f, 0.0f, 0.0f, "Error compiling fragment shader '%s':", strrchr(m_FileName, '\\') + 1);
		printInfoLog(fs);
        return false;
	}

	// Criar um objecto e ligar os dois shaders já compilados
    m_Handle = glCreateProgramObjectARB();
    glAttachObjectARB(m_Handle, vs);
    glAttachObjectARB(m_Handle, fs);

	Link();

    return true;
}
Exemplo n.º 16
0
bool    loadShader ( GLhandleARB shader, const char * fileName )
{
    printf ( "Loading %s\n", fileName );

	FILE * file = fopen ( fileName, "rb" );

	if ( file == NULL )
	{
		printf ( "Error opening %s\n", fileName );
		exit   ( 1 );
	}

	fseek ( file, 0, SEEK_END );

	GLint size = ftell ( file );

	if ( size < 1 )
	{
		fclose ( file );
		printf ( "Error loading file %s\n", fileName );
		exit   ( 1 );
	}

	char * buf = (char *) malloc ( size );

	fseek ( file, 0, SEEK_SET );

	if ( fread ( buf, 1, size, file ) != size )
	{
		fclose ( file );
		printf ( "Error loading file %s\n", fileName );
		exit   ( 1 );
	}

	fclose ( file );

    GLint   compileStatus;

    glShaderSourceARB ( shader, 1, (const char **) &buf, &size );

	free ( buf );
                                        // compile the particle vertex shader, and print out
    glCompileShaderARB ( shader );

    if ( !checkOpenGLError() )          // check for OpenGL errors
        return false;

    glGetObjectParameterivARB ( shader, GL_OBJECT_COMPILE_STATUS_ARB, &compileStatus );
    printInfoLog              ( shader );

    return compileStatus != 0;
}
Exemplo n.º 17
0
GLuint hglCreateProgram(const GLchar *vss, const GLchar *fss)
{
	GLuint vertex = glCreateShader(GL_VERTEX_SHADER);
	GLuint fragment = glCreateShader(GL_FRAGMENT_SHADER);
	
	glShaderSource(vertex, 1, &vss, 0);
	glShaderSource(fragment, 1, &fss, 0);
	
	glCompileShader(vertex);
	glCompileShader(fragment);
	
	GLint status;
	glGetShaderiv(vertex, GL_COMPILE_STATUS, &status);

	if( status != GL_TRUE ) {
		std::cerr << "Vertex Shader Compilation Failed" << std::endl;
	}
	
	glGetShaderiv(fragment, GL_COMPILE_STATUS, &status);

	if( status != GL_TRUE ) {
		std::cerr << "Fragment Shader Compilation Failed" << std::endl;
	}
	
	printInfoLog(vertex);
	printInfoLog(fragment);
	
	GLuint program = glCreateProgram();
	glAttachShader(program, vertex);
	glAttachShader(program, fragment);
	glLinkProgram(program);
	
	// Allow GL to delete shaders once program is deleted.
	glDeleteShader(vertex);
	glDeleteShader(fragment);
	
	return program;
}
static unsigned int _initShader(const char *vs_source, const char *fs_source)
{
	GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
	glShaderSource(vertex_shader, 1, &vs_source, NULL);
	glCompileShader(vertex_shader);
	printInfoLog(vertex_shader);

	GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
	glShaderSource(fragment_shader, 1, &fs_source, NULL);
	glCompileShader(fragment_shader);
	printInfoLog(fragment_shader);

	unsigned int shader_program = glCreateProgram();
	glAttachShader(shader_program, vertex_shader);
	glAttachShader(shader_program, fragment_shader);
	glLinkProgram(shader_program);
	printInfoLog(shader_program);

	glDeleteShader(vertex_shader);
	glDeleteShader(fragment_shader);

	return shader_program;
}
Exemplo n.º 19
0
bool Shader::Link()
{
	int linked;

    glLinkProgramARB(m_Handle);

    glGetObjectParameterivARB(m_Handle, GL_OBJECT_LINK_STATUS_ARB, &linked);

    if (!linked)
	{
		printInfoLog(m_Handle);
        return false;
	}

    return true;
}
Exemplo n.º 20
0
Arquivo: Shader.cpp Projeto: NCCA/NGL
void Shader::loadFromString(const std::string &_string ) noexcept
{
  // see if we already have some source attached
  if(m_source.size()!=0)
  {
    msg->addWarning("deleting existing source code\n");
    m_source.clear();
  }

  // we need this for the check in the compile bit
  m_source=_string;
  const char* data=m_source.c_str();

  glShaderSource(m_shaderHandle , 1, &data,nullptr);
  m_compiled=false;
 if (m_debugState == true)
  {
    printInfoLog(m_shaderHandle);
  }
}
Exemplo n.º 21
0
void shader::reload()
{
	GLenum err;
	//std::cerr << "reloading " << vert << ", " << frag << std::endl;
	glDetachObjectARB(shaderobj, vertexshader);
	glDetachObjectARB(shaderobj, fragmentshader);

	vertexshader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
	fragmentshader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);

	char * source;
	source = GetSource(vert);
	glShaderSourceARB(vertexshader, 1, (const GLcharARB**)&source, NULL);

	source = GetSource(frag);
	glShaderSourceARB(fragmentshader, 1, (const GLcharARB**)&source, NULL);

	// compile the fragment and vertex shader
	glCompileShader(vertexshader);
	glCompileShader(fragmentshader);

	// attach shaders to shader obj
	glAttachObjectARB(shaderobj, vertexshader);
	glAttachObjectARB(shaderobj, fragmentshader);

	// link the shader obj and check status
	glLinkProgramARB(shaderobj);
	printInfoLog(shaderobj);

	//t_tex = 0;
	for(size_t i=0; i<value.size(); i++)
	{
		if(type.at(i)=='t') continue;//n_tex++;
		setUniform(i,value.at(i));
	}

	if((err=glGetError())!=0) {
		printf("\n%s: %d\n", __func__, __LINE__);
		exit(1);
	}
}
Exemplo n.º 22
0
void Shader::compile() noexcept
{
  if (m_source.empty() )
  {
    std::cerr<<"Warning no shader source loaded\n";
    return;
  }

  glCompileShader(m_shaderHandle);
  if(m_debugState==true)
  {
    GLint infologLength = 0;
    std::cerr <<"Compiling Shader "<<m_name<<"\n";
    glGetShaderiv(m_shaderHandle, GL_COMPILE_STATUS,&infologLength);
    if( infologLength == GL_FALSE)
    {
      std::cerr<<"Shader compile failed or had warnings \n";
      printInfoLog(m_shaderHandle);
      //exit(EXIT_FAILURE);
    }
  }
  m_compiled=true;
}
Exemplo n.º 23
0
GLhandleARB prepareShader (GLhandleARB vert, GLhandleARB frag, const char * path_vert, const char * path_frag)
{
        GLint       local_linked;
        GLhandleARB local;

                                        // create a vertex shader object and a fragment shader object
    vert   = glCreateShaderObjectARB ( GL_VERTEX_SHADER_ARB   );
    frag = glCreateShaderObjectARB ( GL_FRAGMENT_SHADER_ARB );

                                        // load source code strings into shaders
    if ( !loadShader ( vert, path_vert ) )
        exit ( 1 );

    if ( !loadShader ( frag, path_frag ) )
        exit ( 1 );
                                        // create a program object and attach the
                                        // two compiled shaders
    local = glCreateProgramObjectARB ();

    glAttachObjectARB ( local, vert   );
    glAttachObjectARB ( local, frag );

                                        // link the program object and print out the info log
    glLinkProgramARB ( local );

    if ( !checkOpenGLError() )          // check for OpenGL errors
        exit ( 1 );

    glGetObjectParameterivARB ( local, GL_OBJECT_LINK_STATUS_ARB, &local_linked );

    printInfoLog ( local);
    if ( !local_linked )
        exit(0);

    return local;

}
Exemplo n.º 24
0
	bool CShaderManager::addShader(GLint shaderIndex, string vertexFile, string fragmentFile)
	{
		GLhandleARB v,f;

		v = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
		f = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);

		string _v = textFileRead(vertexFile);
		string _f = textFileRead(fragmentFile);

		if (_v=="" || _f=="")
		{
			lastError = "Shader files missing or invalid!";
			return false;
		}

		const char * vv = _v.c_str();
		const char * ff = _f.c_str();

		glShaderSourceARB(v,1,&vv,NULL);
		glShaderSourceARB(f,1,&ff,NULL);

		glCompileShaderARB(v);
		glCompileShaderARB(f);

		GLhandleARB shaderProgram = glCreateProgramObjectARB();

		glAttachObjectARB(shaderProgram,v);
		glAttachObjectARB(shaderProgram,f);

		glLinkProgramARB(shaderProgram);

		shaderPrograms[shaderIndex]=ShaderData(shaderProgram);

		return printInfoLog(shaderProgram);
	}
Exemplo n.º 25
0
void moShaderGLSL::PrintFragShaderLog()
{
    if (m_FragmentShader != 0) printInfoLog(m_FragmentShader);
}
Exemplo n.º 26
0
void moShaderGLSL::PrintVertShaderLog()
{
    if (m_VertexShader != 0) printInfoLog(m_VertexShader);
}
Exemplo n.º 27
0
void
initShader(void)
{
    ///////////////////////////////////////////////////////////////////////////
    //
    // Create earth shader
    //
    GLhandleARB terrain_vertex_shader;
    GLhandleARB terrain_fragment_shader;

    //
    // Create and load resources
    //
    g_terrainProgram          = glCreateProgramObjectARB();
    terrain_vertex_shader     = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
    terrain_fragment_shader   = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);

    loadShaderFromFile(terrain_vertex_shader, "shader/terrain.vert");
    loadShaderFromFile(terrain_fragment_shader, "shader/terrain.frag");

    //
    // Compile
    //
    glCompileShaderARB(terrain_vertex_shader);
    GET_GLERROR(0);
    printInfoLog(terrain_vertex_shader);

    glCompileShaderARB(terrain_fragment_shader);
    GET_GLERROR(0);
    printInfoLog(terrain_fragment_shader);

    //
    // Link
    //
    glAttachObjectARB(g_terrainProgram, terrain_vertex_shader);
    glAttachObjectARB(g_terrainProgram, terrain_fragment_shader);
    glLinkProgramARB(g_terrainProgram);
    GET_GLERROR(0);
    printInfoLog(g_terrainProgram);

    ///////////////////////////////////////////////////////////////////////////
    //
    // Setup terrain shader
    //

    //
    // Sampler
    //
    glUseProgramObjectARB(g_terrainProgram);
	GET_GLERROR(0);

	float test;
    //
    // Aufgabe 1.b - Begin
    //
	
	int samplerTerrain = glGetUniformLocationARB(g_terrainProgram, "samplerTerrain");
	GET_GLERROR(0);
	int samplerGradient = glGetUniformLocationARB(g_terrainProgram, "samplerGradient");
	GET_GLERROR(0);

	glUniform1i(samplerTerrain, 0);
	GET_GLERROR(0);
	glUniform1i(samplerGradient, 1);
	GET_GLERROR(0);
    //
    // Aufgabe 1.b - End
    //

	//
	// Bounding Box
	//
	int LLFLocation = glGetUniformLocationARB(g_terrainProgram, "v3LLF");
	GET_GLERROR(0);
	int URBLocation = glGetUniformLocationARB(g_terrainProgram, "v3URB");
	GET_GLERROR(0);

	vec3 LLF = vec3(g_sceneAABB.xMin, g_sceneAABB.yMin, g_sceneAABB.zMin);
	vec3 URB = vec3(g_sceneAABB.xMax, g_sceneAABB.yMax, g_sceneAABB.zMax);

    glUniform3fARB(LLFLocation, g_sceneAABB.xMin, g_sceneAABB.yMin, g_sceneAABB.zMin);
	GET_GLERROR(0);
	glUniform3fARB(URBLocation, g_sceneAABB.xMax, g_sceneAABB.yMax, g_sceneAABB.zMax);
	GET_GLERROR(0);
    return;
}