void cube::loadCubeShaders()
{
	char *vsSource = file2string("shaders/sky.vert");
	char *fsSource = file2string("shaders/sky.frag");	

	cube_vs = glCreateShader(GL_VERTEX_SHADER);
	glShaderSource(cube_vs, 1, &vsSource, NULL);
	glCompileShader(cube_vs);
	GLint a;
	glGetShaderiv(cube_vs, GL_COMPILE_STATUS, &a);
	printf("VS SHADER STATUS: %d\n", a);

	cube_fs = glCreateShader(GL_FRAGMENT_SHADER);
	glShaderSource(cube_fs, 1, &fsSource, NULL);
	glCompileShader(cube_fs);
	glGetShaderiv(cube_fs, GL_COMPILE_STATUS, &a);
	printf("FS SHADER STATUS: %d\n", a);

	free(vsSource);
	free(fsSource);

	cubeProgram = glCreateProgram();
	glAttachShader(cubeProgram, cube_vs);
	glAttachShader(cubeProgram, cube_fs);
	glLinkProgram(cubeProgram);
	GLint b;
	glGetProgramiv(cubeProgram, GL_LINK_STATUS, &a);
	glValidateProgram(cubeProgram);
	glGetProgramiv(cubeProgram, GL_VALIDATE_STATUS, &b);
	printf("Cube Program STATUS: link %d validate %d\n", a, b);
	
}
Beispiel #2
0
void pqXmlView::openFile(QString file) {
    this->file = file;

    setPlainText(file2string(file));
    new XmlSyntaxHighlighter(document());
    setLineWrapMode(QTextEdit::NoWrap);
}
Beispiel #3
0
bool Shader::compileShader(GLuint* shader, GLenum type, char file[])
{
    GLint status;
    const GLchar *source;
    
    source = file2string(file);
    if (!source)
    {
        printf("Erro ao carregar o shader!\n");
        return false;
    }
    *shader = glCreateShader(type);
    glShaderSource(*shader, 1, &source, NULL);
    glCompileShader(*shader);
    
    GLint logLength;
    glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength);
    if (logLength > 0)
    {
        GLchar *log = (GLchar *)malloc(logLength);
        glGetShaderInfoLog(*shader, logLength, &logLength, log);
        printf("Shader compile log:\n%s", log);
        free(log);
    }
    free((void*)source);
    
    glGetShaderiv(*shader, GL_COMPILE_STATUS, &status);
    if(status == 0)
    {
        glDeleteShader(*shader);
        return false;
    }
    return true;
}
Beispiel #4
0
int initiateShaders(string vertexShader, string fragmentShader){
	glewInit();
	if (GLEW_VERSION_2_0)
		fprintf(stderr, "INFO: OpenGL 2.0 supported, proceeding\n");
	else
	{
		fprintf(stderr, "INFO: OpenGL 2.0 not supported. Exit\n");
		return EXIT_FAILURE;
	}
	
	
		/* The vertex shader */
	const GLchar *vsSource = file2string(vertexShader.c_str());
	const GLchar *fsSource = file2string(fragmentShader.c_str());
 
	/* Compile and load the program */
 
	GLuint vs, /* Vertex Shader */
		   fs, /* Fragment Shader */
		   sp; /* Shader Program */
 
 
	vs = glCreateShader(GL_VERTEX_SHADER);
	glShaderSource(vs, 1, &vsSource, NULL);
	glCompileShader(vs);
	printLog(vs);
 
	fs = glCreateShader(GL_FRAGMENT_SHADER);
	glShaderSource(fs, 1, &fsSource, NULL);
	glCompileShader(fs);
	printLog(fs);
 
	free((void*)vsSource);
	free((void*)fsSource);
 
	sp = glCreateProgram();
	glAttachShader(sp, vs);
	glAttachShader(sp, fs);
	glLinkProgram(sp);
	printLog(sp);
 
	glUseProgram(sp);
	
	return EXIT_SUCCESS;
}
Beispiel #5
0
/** load <fileName> to textarea with error check
 */
bool CodeMirrorFile::loadFile(QString fileName) {
    try {
        setPlainText(file2string(path_ = fileName));
    }
    catch(std::exception& e) {
        return error(e.what());
    }
    return true;
}
Beispiel #6
0
/// Reads a GLSL shader from a file.
// The file is only read and the shader created. No compilation.
GLuint file2shader(const char* filepath, GLenum shader_type) {
    GLuint shader = glCreateShader(shader_type);
    if (!shader) {
        throw std::runtime_error(
                std::string("Couldn't create shader."));
    }
    std::string src = file2string(filepath);
    const char* data[] = {src.c_str()};
    glShaderSource(shader, 1, data, NULL);
    return shader;
}
	Shader::Shader(const std::string &vertexPath,const std::string &fragmentPath )
	{
		this->fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
		this->vertexShader = glCreateShader(GL_VERTEX_SHADER);
		this->shaderProgram = glCreateProgram();
        
		if (vertexPath != "")
		{
			const char *vShader = file2string(Assets::GetContentPath() + vertexPath);
            
			if (vShader){
				glShaderSource(vertexShader, 1, &vShader, NULL);
				glCompileShader(vertexShader);
				printLog(vertexShader);
                
				free((void*)vShader);
                
				glAttachShader(shaderProgram, vertexShader);
			}
		}
        
		if (fragmentPath != "")
		{
			const char *fShader = file2string(Assets::GetContentPath() + fragmentPath);
            
			if (fShader){
				glShaderSource(fragmentShader, 1, &fShader, NULL);
				glCompileShader(fragmentShader);
				printLog(fragmentShader);
                
				free((void*)fShader);
                
				glAttachShader(shaderProgram, fragmentShader);
			}
		}
        
		glLinkProgram(shaderProgram);
		printLog(shaderProgram);
	}
Beispiel #8
0
/** create a new Prolog script
 */
void spqrMainWindow::newFile() {
    if (!checkSave())
        return;

    QFileDialog fd(this, tr("New Prolog File"), lastDir, Prolog_Exts());
    fd.setAcceptMode(fd.AcceptSave);
    fd.setDefaultSuffix("lp");
    if (fd.exec()) {
        QString newPath = fd.selectedFiles()[0];
        QString script = file2string(":/prolog/newFileDefaultScript.pl")
                .arg(newPath, QDateTime::currentDateTime().toString(), QFileInfo(newPath).baseName().replace(' ', '_'));
        source()->setPlainText(script);
        source()->setPath(newPath);
        initSourceTitle(true);
        saveFile();
    }
}
Beispiel #9
0
void _cbHBKWIN(WM_MESSAGE * pMsg)
{
	int NCode;
	TREEVIEW_ITEM_Handle Sel;
	int Id;
	char pBuffer[128];
	
	switch (pMsg->MsgId)
	{
		case WM_NOTIFY_PARENT:
			NCode = pMsg->Data.v;
			Id = WM_GetId(pMsg->hWinSrc);
			if (Id == GUI_ID_TREEVIEW0)
			{
				switch (NCode)
				{
					case WM_NOTIFICATION_CLICKED:
						//printf("switching focus to treeview\n");
						WM_SetFocus(pMsg->hWinSrc);
						break;
					case WM_NOTIFICATION_RELEASED:
						Sel = TREEVIEW_GetSel(pMsg->hWinSrc);
						TREEVIEW_ITEM_GetText(Sel, (U8*)pBuffer, 128);
						printf("Selecting \"%s\"\n", pBuffer);
						
						myfd_t * selfd = (myfd_t *) TREEVIEW_ITEM_GetUserData(Sel);
						printf("Path to selection : %s\n", selfd->path);
						if (selfd->type == 0)
						{
							printf("is a directory\n");
						} else {
							printf("is a file\n");
							char * file_str = file2string(selfd->path);
							db = string2database(file_str);
							if (db)
							{
								run_db();
							} else {
								printf("Error loading database\n");
							}
						}
						
						break;
					case WM_NOTIFICATION_SEL_CHANGED:
						printf("Selection changed\n");
						break;
				}
			}
			else if (Id == GUI_ID_MULTIEDIT0)
			{
				switch (NCode)
				{
					case WM_NOTIFICATION_CLICKED:
						//printf("switching focus to terminal\n");
						WM_SetFocus(pMsg->hWinSrc);
						break;
					case WM_NOTIFICATION_VALUE_CHANGED:
						//printf("WM_NOTIFICATION_VALUE_CHANGED\n");
						break;
				}
			}
			else if (Id == GUI_ID_USER+0)
			{
				switch (NCode)
				{
					case WM_NOTIFICATION_CLICKED:
						WM_SetFocus(pMsg->hWinSrc);
						break;
				}
			}
			break;
		
		case WM_PAINT:
			GUI_SetColor(GUI_WHITE);
			GUI_Clear();
			break;

		default:
			WM_DefaultProc(pMsg);
	}
}
Beispiel #10
0
 inline std::string file2string(const std::string& name) throw(Error_file2string::open_file, std::ios_base::failure) {
   return file2string(name.c_str());
 }