Пример #1
0
GLuint loadShader(const char* vertexFile, const char* fragmentFile)
{
    GLuint vert, frag, program;
	if (oglError() != GL_NO_ERROR) /* just in case an error occurred beforehand */
		printf("NOTE: GL error set before call to loadShader()\n");
	
	/* load vertex and fragment shaders */
	vert = loadShaderPart(vertexFile, GL_VERTEX_SHADER);
	frag = loadShaderPart(fragmentFile, GL_FRAGMENT_SHADER);
	
	if (!vert && !frag)
		return 0;
	
	/* create the shader program object */
	program = glCreateProgram();
	
	/* attach the shader objects to the program */
	if (vert) glAttachShader(program, vert);
	if (frag) glAttachShader(program, frag);
	
	/* link the attached shader objects to create the shader executable */
	glLinkProgram(program);
	
	/* check for errors */
	programError(program);
	
	/* now it's compiled we don't need the intermediates */
	if (vert) glDeleteShader(vert);
	if (frag) glDeleteShader(frag);
	
	/* return our shader program */
    oglError();
	return program;
}
Пример #2
0
/* Load vertex and fragment shader and return the compiled program */
GLuint GLWrapper::LoadShader(const char *vertex_path, const char *fragment_path)
{
    GLuint vertShader, fragShader;

    // Read shaders
    std::string vertShaderStr = readFile(vertex_path);
    std::string fragShaderStr = readFile(fragment_path);

    GLint result = GL_FALSE;
    int logLength;

    vertShader = BuildShader(GL_VERTEX_SHADER, vertShaderStr);
    fragShader = BuildShader(GL_FRAGMENT_SHADER, fragShaderStr);

    std::cout << "Linking program" << std::endl;
    GLuint program = glCreateProgram();
    glAttachShader(program, vertShader);
    glAttachShader(program, fragShader);
    glLinkProgram(program);

    glGetProgramiv(program, GL_LINK_STATUS, &result);
    glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
    std::vector<char> programError((logLength > 1) ? logLength : 1);
    glGetProgramInfoLog(program, logLength, NULL, &programError[0]);
    std::cout << &programError[0] << std::endl;

    glDeleteShader(vertShader);
    glDeleteShader(fragShader);

    return program;
}
Пример #3
0
Файл: rtm.c Проект: 8l/linoleum
/**
 * Initialize a certain section, pWorkspace or pCode
 * @param size The size of the section
 * @param section Pointer to the section pointer
 * @param section Name of the section
 */
void init_section(unit ** section, int size, const char *section_name)
{
	if (size != 0) {
		*section = (unit *) calloc(size, sizeof(unit));
		if (*section == NULL) {
			printf("calloc (%d, %d)\n", size, (int) sizeof(unit));
			printf
			    ("ERROR: Failed to allocate memory for %s section.",
			     section_name);
			programError("");
		} else
			memset(*section, '\0', size * sizeof(unit));
	} else {
		printf("ERROR: Empty %s section.", section_name);
		programError("");
	}
}
Пример #4
0
/* Load the editor program into Lua. Returns 0 on success, 1 on error. */
int loadProgram(void) {
    int buflen;
    char *buf = editorRowsToString(&buflen);

    if (luaL_loadbuffer(l81.L,buf,buflen,l81.filename)) {
        programError(lua_tostring(l81.L, -1));
        free(buf);
        return 1;
    }
    free(buf);
    if (lua_pcall(l81.L,0,0,0)) {
        programError(lua_tostring(l81.L, -1));
        return 1;
    }
    l81.luaerr = 0;
    editorClearError();
    return 0;
}
Пример #5
0
Файл: rtm.c Проект: 8l/linoleum
void
read_section(unit ** section, int position, int size, const char *section_name)
{
	/* set file pointer */
	if (fseek(openFile, position, SEEK_SET) == -1) {
		fclose(openFile);
		printf("ERROR: %s section not found.", section_name);
		programError("");
	}
	/* read initialized workspace */
	readBytes =
	    fread(*section, sizeof(char), size * sizeof(unit), openFile);
	if (readBytes != size * sizeof(unit)) {
		fclose(openFile);
		printf("ERROR: Failed to read %s section.", section_name);
		programError("");
	}
}
Пример #6
0
GLuint LoadShader(const char* vertex_path, const char* fragment_path)
{
    GLuint vertShader = glCreateShader(GL_VERTEX_SHADER);
    GLuint fragShader = glCreateShader(GL_FRAGMENT_SHADER);

    // Read shaders
    std::string vertShaderStr = readFile(vertex_path);
    std::string fragShaderStr = readFile(fragment_path);
    const char* vertShaderSrc = vertShaderStr.c_str();
    const char* fragShaderSrc = fragShaderStr.c_str();

    GLint result = GL_FALSE;
    int logLength;

    // Compile vertex shader
    glShaderSource(vertShader, 1, &vertShaderSrc, NULL);
    glCompileShader(vertShader);

    // Check vertex shader
    glGetShaderiv(vertShader, GL_COMPILE_STATUS, &result);
    glGetShaderiv(vertShader, GL_INFO_LOG_LENGTH, &logLength);
    // Handle error output
    std::vector<char> vertShaderError((logLength > 1) ? logLength : 1);
    glGetShaderInfoLog(vertShader, logLength, NULL, &vertShaderError[0]);
    std::cout << &vertShaderError[0] << std::endl;

    // Compile fragment shader
    std::cout << "Compiling fragment shader." << std::endl;
    glShaderSource(fragShader, 1, &fragShaderSrc, NULL);
    glCompileShader(fragShader);

    // Check fragment shader
    glGetShaderiv(fragShader, GL_COMPILE_STATUS, &result);
    glGetShaderiv(fragShader, GL_INFO_LOG_LENGTH, &logLength);
    //Handle error output
    std::vector<char> fragShaderError((logLength > 1) ? logLength : 1);
    glGetShaderInfoLog(fragShader, logLength, NULL, &fragShaderError[0]);
    std::cout << &fragShaderError[0] << std::endl;

    std::cout << "Linking program" << std::endl;
    GLuint program = glCreateProgram();
    glAttachShader(program, vertShader);
    glAttachShader(program, fragShader);
    glLinkProgram(program);

    glGetProgramiv(program, GL_LINK_STATUS, &result);
    glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
    std::vector<char> programError( (logLength > 1) ? logLength : 1 );
    glGetProgramInfoLog(program, logLength, NULL, &programError[0]);
    std::cout << &programError[0] << std::endl;

    glDeleteShader(vertShader);
    glDeleteShader(fragShader);

    return program;
}
Пример #7
0
void draw(void) {
    lua_getglobal(l81.L,"draw");
    if (!lua_isnil(l81.L,-1)) {
        if (lua_pcall(l81.L,0,0,0)) {
            programError(lua_tostring(l81.L, -1));
        }
    } else {
        lua_pop(l81.L,1);
    }
}
Пример #8
0
int polygonBinding(lua_State *L) {
  Sint16* polyBufferX;
  Sint16* polyBufferY;

  if (!(lua_gettop(L) == 2 && lua_istable(L,-1) && lua_istable(L,-2))) {
      programError("Invalid arguments for polygon");
      return 0;
  }

  int size = (int)lua_objlen(L,-1), i=0;
  polyBufferY = (Sint16*)malloc(size * sizeof(Sint16));
  lua_pushnil(L);
  while(lua_next(L,-2) != 0) {
    polyBufferY[i++] = (Sint16)lua_tonumber(L,-1);
    lua_pop(L,1);
    if (i > size) break;
  }

  lua_pop(L,1);

  if (size != (int)lua_objlen(L,-1)) {
    programError("Array size mismatch in call to polygon");
    return 0;
  }
  polyBufferX = (Sint16*)malloc(size * sizeof(Sint16));
  lua_pushnil(L);
  i=0;
  while(lua_next(L,-2) != 0) {
    polyBufferX[i++] = (Sint16)lua_tonumber(L,-1);
    lua_pop(L,1);
    if (i > size) break;
  }

  drawPolygon(l81.fb, polyBufferX, polyBufferY, size, l81.r, l81.g, l81.b, l81.alpha, l81.filled);

  free(polyBufferX);
  free(polyBufferY);
  return 0;
}
Пример #9
0
GLuint Shader::LoadShader(const char* vertPath, const char* fragPath) { 
    //generate shader names
    GLuint vertShader = glCreateShader(GL_VERTEX_SHADER);
    GLuint fragShader = glCreateShader(GL_FRAGMENT_SHADER);

    //get shader src
    string vertShaderStr = ReadFile(vertPath);
    string fragShaderStr = ReadFile(fragPath);

    const char* vertShaderSrc = vertShaderStr.c_str();
    const char* fragShaderSrc = fragShaderStr.c_str();

    GLint result = GL_FALSE;
    int logLength;

    //compile vertex shader
    glShaderSource(vertShader, 1, &vertShaderSrc, NULL);
    glCompileShader(vertShader);
    glGetShaderiv(vertShader, GL_COMPILE_STATUS, &result);
    glGetShaderiv(vertShader, GL_INFO_LOG_LENGTH, &logLength);
    vector<char> vertShaderError(logLength);
    glGetShaderInfoLog(vertShader, logLength, NULL, &vertShaderError[0]);
    cout << &vertShaderError[0] << endl;

    //compile fragment shader
    glShaderSource(fragShader, 1, &fragShaderSrc, NULL);
    glCompileShader(fragShader);
    glGetShaderiv(fragShader, GL_COMPILE_STATUS, &result);
    glGetShaderiv(fragShader, GL_INFO_LOG_LENGTH, &logLength);
    vector<char> fragShaderError(logLength);
    glGetShaderInfoLog(fragShader, logLength, NULL, &fragShaderError[0]);
    cout << &fragShaderError[0] << endl; 

    //link the program
    GLuint program = glCreateProgram();
    glAttachShader(program, vertShader);
    glAttachShader(program, fragShader);
    glLinkProgram(program);

    glGetProgramiv(program, GL_LINK_STATUS, &result);
    glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
    vector<char> programError(logLength > 1 ? logLength : 1);
    glGetProgramInfoLog(program, logLength, NULL, &programError[0]);
    cout << &programError[0] << endl;

    glDeleteShader(vertShader);
    glDeleteShader(fragShader);

    return program;
}
Пример #10
0
Файл: rtm.c Проект: 8l/linoleum
/* the program */
int main(int argc, char **argv, char **env)
{
	int i, toAdd, parameterLen;
	proc_t isokernelP;

	environment = env;

	/* initialize IParagraph */
	IParagraph = (struct LNLMINIT *) &ipData[8];
	/* check the size of the application name */
	if (strlen(argv[0]) >= 32768)
		programError("ERROR: Application name too long.");
	/* read application name into: dmsStockFilename */
	/* translate the references to a real path */
	realpath(argv[0], dmsStockFilename);

	/* - reads commandline parameters into: dmsParameters */
	dmsParameters[0] = '\0';
	parameterLen = 0;
	for (i = 1; i < argc; i++) {
		/* check if there are spaces in the current entry */
		if (strchr(argv[i], ' ') == NULL) {
			/* just insert string */
			toAdd = strlen(argv[i]);
			if ((parameterLen + toAdd + 1) >= 32768)
				programError
				    ("ERROR: Too many commandline parameters.");

			strcpy(&dmsParameters[parameterLen], argv[i]);
			parameterLen += toAdd;
			strcpy(&dmsParameters[parameterLen], " ");
			parameterLen++;
		} else {
			/* surround string by quotes */
			toAdd = strlen(argv[i]);
			if ((parameterLen + toAdd + 3) >= 32768)
				programError
				    ("ERROR: Too many commandline parameters.");

			strcat(&dmsParameters[parameterLen], "\"");
			parameterLen++;
			strcat(&dmsParameters[parameterLen], argv[i]);
			parameterLen += toAdd;
			strcat(&dmsParameters[parameterLen], "\" ");
			parameterLen++;
		}
	}
	/* terminate the parameter string if necessary */
	if (parameterLen > 0)
		dmsParameters[--parameterLen] = '\0';

	/* allocate and initialize L.IN.OLEUM code area */
	init_section(&pCode, IParagraph->app_code_size, "code");
	/* allocate and initialize application workspace */
	init_section(&pWorkspace, IParagraph->default_ramtop, "workspace");
	current_ramtop = IParagraph->default_ramtop;

	/* open stockfile for reading */
	openFile = fopen(dmsStockFilename, "r");
	if (!openFile)
		programError("ERROR: Failed to open Stockfile");

	/* read the initialised workspace */
	read_section(&pWorkspace,
		     IParagraph->physwsentry,
		     IParagraph->app_ws_size, "workspace");
	/* set pointer to uninitialized workspace */
	pUIWorkspace = &pWorkspace[IParagraph->app_ws_size];
	/* read the code section */
	read_section(&pCode,
		     (IParagraph->app_ws_size * sizeof(unit)) +
		     IParagraph->physwsentry, IParagraph->app_code_size,
		     "code");
	/* set pointer to application start address */
	pCodeEntry = (proc_t) (unit) & pCode[IParagraph->app_code_entry];

	/* close file handle */
	fclose(openFile);

	/* transfer commandline parameters */
	btrsstring(&pUIWorkspace[mm_ProcessCommandLine], dmsParameters);

	/* initialize rest of workspace */
	isokernelP = isokernel;
	pWorkspace[mm_ProcessOrigin] = (unit) pCode;
	pUIWorkspace[mm_ProcessISOcall] = ((unit) isokernelP - (unit) pCode);
	pUIWorkspace[mm_ProcessRAMtop] = IParagraph->default_ramtop;
	pUIWorkspace[mm_ProcessPriority] = IParagraph->app_code_pri;

	/* setup isokernel */
	PRINT("initializing ISOKERNEL...\n");
	assert(lino_display_init(IParagraph->lfb_x_atstartup,
				 IParagraph->lfb_y_atstartup,
				 IParagraph->lfb_w_atstartup,
				 IParagraph->lfb_h_atstartup, NULL));
	assert(initPointerCommand());
	assert(initNetCommand());

	PRINT1("%s: run main linoleum program.\n", __func__);

	linoleum();
	if (xAtExit == FAIL) {
		int size = 256, n, result;
		char *arguments = malloc(size);
		while (1) {
			n = snprintf(arguments,
				     size,
				     "xmessage -center \"%s\n\nRegisters after execution.\nA: %d\nB: %d\nC: %d\nD: %d\nE: %d\nX: %d\n\"",
				     dmsStockFilename,
				     (int) aAtExit,
				     (int) bAtExit,
				     (int) cAtExit,
				     (int) dAtExit,
				     (int) eAtExit, (int) xAtExit);
			if (n > -1 && n < size)
				break;
			if (n > -1)
				size = n + 1;
			else
				size *= 2;

			arguments = realloc(arguments, size);
		}
		result = system(arguments);
		free(arguments);
		if (result != 0) {
			printf(dmsStockFilename);
			printf("Registers after execution.\n");
			printf("A: %d\n", (int) aAtExit);
			printf("B: %d\n", (int) bAtExit);
			printf("C: %d\n", (int) cAtExit);
			printf("D: %d\n", (int) dAtExit);
			printf("E: %d\n", (int) eAtExit);
			printf("X: %d\n", (int) xAtExit);
		}
	}

	/* break down isokernel */
	PRINT("Clear remaining isokernel stuff\n");
	lino_display_close();

	/* free allocated memory */
	free(pCode);
	free(pWorkspace);

	/* terminate program */
	return (0);
}
Пример #11
0
// load shaders
bool ShaderLoader::loadShader(const char *vertex_path, const char *fragment_path, GLuint &program)
{
    // create shaders
    GLuint vertShader = glCreateShader(GL_VERTEX_SHADER);
    GLuint fragShader = glCreateShader(GL_FRAGMENT_SHADER);

    // read shaders
    std::string vertShaderStr = readFile(vertex_path);
    std::string fragShaderStr = readFile(fragment_path);
    const char *vertShaderSrc = vertShaderStr.c_str();
    const char *fragShaderSrc = fragShaderStr.c_str();

    // hold results
    GLint result = GL_FALSE;
    int logLength;

    // compile vertex shader
    glShaderSource(vertShader, 1, &vertShaderSrc, NULL);
    glCompileShader(vertShader);

    // check vertex shader
    glGetShaderiv(vertShader, GL_COMPILE_STATUS, &result);

        // failed compile
        if(!result)
        {
            glGetShaderiv(vertShader, GL_INFO_LOG_LENGTH, &logLength);
            std::vector<char> vertShaderError((logLength > 1) ? logLength : 1);
            glGetShaderInfoLog(vertShader, logLength, NULL, &vertShaderError[0]);
            std::cerr << "[F] FAILED TO COMPILE VERTEX SHADER!" << &vertShaderError[0] << std::endl;
            return false;
        }

    // compile fragment shader
    glShaderSource(fragShader, 1, &fragShaderSrc, NULL);
    glCompileShader(fragShader);

    // check fragment shader
    glGetShaderiv(fragShader, GL_COMPILE_STATUS, &result);

        // failed compile
        if(!result)
        {
            glGetShaderiv(fragShader, GL_INFO_LOG_LENGTH, &logLength);
            std::vector<char> fragShaderError((logLength > 1) ? logLength : 1);
            glGetShaderInfoLog(fragShader, logLength, NULL, &fragShaderError[0]);
            std::cerr << "[F] FAILED TO COMPILE FRAGMENT SHADER!" << &fragShaderError[0] << std::endl;
            return false;
        }

    // create program and link with shaders
    program = glCreateProgram();
    glAttachShader(program, vertShader);
    glAttachShader(program, fragShader);
    glLinkProgram(program);

    // check program status
    glGetProgramiv(program, GL_LINK_STATUS, &result);

        // failed program
        if(!result)
        {
            glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
            std::vector<char> programError( (logLength > 1) ? logLength : 1 );
            glGetProgramInfoLog(program, logLength, NULL, &programError[0]);
            std::cerr << "[F] THE SHADER PROGRAM FAILED TO LINK" << &programError[0] << std::endl;
            return false;
        }

    // delete shaders after attachment
    glDeleteShader(vertShader);
    glDeleteShader(fragShader);

    // return program with shaders
    return true;
}
GLuint ShaderLoader::loadShader()
{
    GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
    GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);

    //Read Shader
    std::string strVertexShader = loadFile(pathVertexShader);
    std::string strFragmentShader = loadFile(pathFragmentShader);
    const char* cStrVertexShader = strVertexShader.c_str();
    const char* cStrFragmentShader = strFragmentShader.c_str();

    GLint result = GL_FALSE;
    int logLength;

    //Compile Vertex Shader
    glShaderSource(vertexShader, 1, &cStrVertexShader, NULL);
    glCompileShader(vertexShader);

    //Check Vertex Shader
    glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &result);
    glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &logLength);
    std::vector<char> vertexShaderError((logLength > 1) ? logLength : 1);
    if(logLength > 1)
    {
        glGetShaderInfoLog(vertexShader, logLength, NULL, 
            &vertexShaderError[0]);
        std::cerr << &vertexShaderError[0] << std::endl;
    }

    //Compile Fragment Shader
    glShaderSource(fragmentShader, 1, &cStrFragmentShader, NULL);
    glCompileShader(fragmentShader);

    //Check Fragment Shader
    glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &result);
    glGetShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &logLength);
    std::vector<char> fragmentShaderError((logLength > 1) ? logLength : 1);
    if(logLength > 1)
    {
        glGetShaderInfoLog(fragmentShader, logLength, NULL, 
            &fragmentShaderError[0]);
        std::cerr << &fragmentShaderError[0] << std::endl;
    }

    //Link Program
    GLuint program = glCreateProgram();
    glAttachShader(program, vertexShader);
    glAttachShader(program, fragmentShader);
    glLinkProgram(program);

    glGetProgramiv(program, GL_LINK_STATUS, &result);
    glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
    std::vector<char> programError( (logLength > 1) ? logLength : 1);
    if(logLength > 1)
    {
        glGetProgramInfoLog(program, logLength, NULL, &programError[0]);
        std::cerr << &programError[0] << std::endl;
    }

    //Return Program
    return program;
}