Exemplo n.º 1
0
	void Shader::LoadVertexShader(const std::string &pFilename){
		// Creation des shaders
		mVShader = glCreateShader(GL_VERTEX_SHADER);

		// Récupération de la source
		std::string filePath = ResourceManager::Call().FindFile(pFilename, "Shader");
		if(filePath == "0")
			throw Exception(String("Vertex Shader file \"")+pFilename+"\" does not exist. Double check file path!");
		File vFile(filePath);
		std::string vSourceStr = vFile.Read();
		const char* vSource = vSourceStr.c_str();
		glShaderSource(mVShader, 1, &vSource, NULL);

		// Compilation
		glCompileShader(mVShader);
		
		// Vérification
		GLint error;
		glGetShaderiv(mVShader, GL_COMPILE_STATUS, &error);
		if(error != GL_TRUE){
			char log[1024];
			glGetShaderInfoLog(mVShader, 1024, NULL, log);
			glDeleteShader(mVShader);
			if(mFShader) 
				glDeleteShader(mFShader);
			if(mGShader)
				glDeleteShader(mGShader);
			throw Exception(String("Vertex Shader Compilation Error (\"")+pFilename+"\") :\n"+log);
		}
	}
Exemplo n.º 2
0
HelpWidget::HelpWidget(QWidget *parent) :
    MainWidget(parent),
    ui(new Ui::HelpWidget)
{
    ui->setupUi(this);
    QString vFileName = QString("%1/help/hallo.html").arg(qApp->applicationDirPath());
    QFile vFile(vFileName);
    if (vFile.open(QIODevice::ReadOnly))
    {
        ui->mpView->setText(vFile.readAll());
    }
}
Exemplo n.º 3
0
void Z3DShaderProgram::loadFromSourceFile(const QString &vertFilename, const QString &geomFilename,
                                          const QString &fragFilename, const QString &header)
{
  m_vertSrcs.clear();
  m_geomSrcs.clear();
  m_fragSrcs.clear();

  // vert
  QString vFilename = Z3DApplication::app()->getShaderPath(vertFilename);
  QFile vFile(vFilename);

  if (!vFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
    throw Exception(QString("Can not open vertex shader file: %1.  Error String: %2").arg(vFilename).arg(vFile.errorString()).toStdString());
  }

  m_vertSrcs.push_back(QString());
  m_vertSrcs[0] = vFile.readAll();
  vFile.close();

  // geom
  if (!geomFilename.isEmpty()) {
    QString gFilename = Z3DApplication::app()->getShaderPath(geomFilename);
    QFile gFile(gFilename);

    if (!gFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
      throw Exception(QString("Can not open geometry shader file: %1.  Error String: %2").arg(gFilename).arg(gFile.errorString()).toStdString());
    }

    m_geomSrcs.push_back(QString());
    m_geomSrcs[0] = gFile.readAll();
    gFile.close();
  }

  // frag
  QString fFilename = Z3DApplication::app()->getShaderPath(fragFilename);
  QFile fFile(fFilename);

  if (!fFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
    throw Exception(QString("Can not open fragment shader file: %1.  Error String: %2").arg(fFilename).arg(fFile.errorString()).toStdString());
  }

  m_fragSrcs.push_back(QString());
  m_fragSrcs[0] = fFile.readAll();
  fFile.close();

  // load
  loadFromSourceCode(m_vertSrcs, m_geomSrcs, m_fragSrcs, header);
}
void CLudeCommandPackageBuildNumber::updateBuildNumber(int inc)
{
    QDir vDir(QDir::currentPath());
    vDir.setNameFilters(QStringList()<<"*.pro");
    QStringList one =  vDir.entryList(QDir::Files);
    if(one.size()!=1){
        qDebug() << "No pro file found.";
        return;
    }

    QString name = one[0].replace(".pro","");
    //NOTE changed cludepackage.json to <package_name>.cde
    QString vPath = QDir::toNativeSeparators(QDir::currentPath()+QLatin1String("/")+name+QLatin1String(".cde"));
    QFile vFile(vPath);
    if(!vFile.exists()){
        qDebug() << "PATH: "<<vPath;
        qDebug() << QString("%1.cde file doesn't exists").arg(name).toLocal8Bit().constData();
    }
    else{
        CLudePackage clp;
        qDebug() << vPath.toLocal8Bit().constData();
        if(clp.fromJsonFile(vPath)){
            clp.setUpdated(QDateTime::currentDateTime().toLocalTime());
            clp.setBuild(clp.build()+inc);
            if(clp.toJsonFile(vPath)){
                qDebug() << "build updated to :"<<clp.build();
            }
            else{
                qDebug() << "failed to update build";
            }
        }
        else{
            qDebug() << QString("%1.cde file parsing error").arg(name).toLocal8Bit().constData();
        }
    }
}
Exemplo n.º 5
0
void vcbList::readVocabList()
     // reads a vocabulary file from fname. It expects the following format:
     // 
     // token_id token_string frequency
{

  int freq=0;
  WordIndex word_id ;
  WordEntry entry("NULL",0) ;

  string line, word ;
  cerr << "Reading vocabulary file from:" << fname << "\n";    
  //  total = 0 ;
  ifstream vFile(fname);
  if(!vFile){
    cerr <<  "\nCannot open vocabulary file " << fname << "file";
    exit(1);
  }
  
  list.push_back(entry);
  s2i[entry.word]=list.size()-1;

  while(getline(vFile, line)){
    istrstream buffer(line.c_str());
    if(!(buffer >> word_id >> word >> freq))
      cerr << "ERROR: reading vocabulary; " << word_id << ' ' << word << ' ' << freq << endl;
    if (word_id == 0){
      cerr << "ERROR: TOKEN ID 0 is reserved for special token NULL, in line: \n"<< line<<"\n" ;
      exit(-1);
    }
    else if (word_id >= MAX_VOCAB_SIZE){
      cerr << "ERROR: TOKEN ID is greater than maximum vocabulary size "
	   << MAX_VOCAB_SIZE << " in line :\n"<< line <<"\n" ;
      exit(-1);
    }	
    else if (freq < 0){
      cerr << "ERROR: frequency must be a positive integer, in line :\n"
	   << line <<"\n";
      exit(-1);
    }
    else if(word_id >= list.size()){
      list.resize(word_id+1);
      list[word_id].word = word ;
      s2i[word]=word_id;
      list[word_id].freq = 0 ;
      noUniqueTokens = word_id + 1 ;
      //      noUniqueTokens++ ;
      //      total += freq ;
    }      
    else if(list[word_id].word != "\0"){
      cerr << "ERROR: TOKEN ID must be unique for each token, in line :\n"
	   << line <<"\n";
      cerr << "TOKEN ID " << word_id << " has already been assigned to: " <<
	list[word_id].word << "\n";
      exit(-1);
    }
    else { // line  has valid information
      list[word_id].word = word ;
      s2i[word]=word_id;
      list[word_id].freq = 0 ;
      //      noUniqueTokens++ ;
      noUniqueTokens  = word_id + 1 ;
      //      total += freq ;
    }
  } // end of while
}