void onDraw(SkCanvas* canvas) override { // The PDF device has already clipped to the content area, but we // do it again here so that the raster and pdf results are consistent. canvas->clipRect(SkRect::MakeWH(SkIntToScalar(320), SkIntToScalar(240))); SkMatrix canvasScale; SkScalar scale = 0.7f; canvasScale.setScale(scale, scale); canvas->concat(canvasScale); // Background shader. SkPaint paint; paint.setShader(MakeShader(559, 387, false))->unref(); SkRect r = SkRect::MakeXYWH(SkIntToScalar(-12), SkIntToScalar(-41), SkIntToScalar(571), SkIntToScalar(428)); canvas->drawRect(r, paint); // Constrained shader. paint.setShader(MakeShader(101, 151, true))->unref(); r = SkRect::MakeXYWH(SkIntToScalar(43), SkIntToScalar(71), SkIntToScalar(101), SkIntToScalar(151)); canvas->clipRect(r); canvas->drawRect(r, paint); }
GLuint PCRender::MakeShaderProgram(const char* vs_text, const char* fs_text) { GLuint program = 0u; GLint program_ok; GLuint vertex_shader = 0u; GLuint fragment_shader = 0u; GLsizei log_length; char info_log[8192]; vertex_shader = MakeShader(GL_VERTEX_SHADER, vs_text); if (vertex_shader != 0u) { fragment_shader = MakeShader(GL_FRAGMENT_SHADER, fs_text); if (fragment_shader != 0u) { /* make the program that connect the two shader and link it */ program = glCreateProgram(); if (program != 0u) { /* attach both shader and link */ glAttachShader(program, vertex_shader); glAttachShader(program, fragment_shader); glLinkProgram(program); glGetProgramiv(program, GL_LINK_STATUS, &program_ok); if (program_ok != GL_TRUE) { fprintf(stderr, "ERROR, failed to link shader program\n"); glGetProgramInfoLog(program, 8192, &log_length, info_log); fprintf(stderr, "ERROR: \n%s\n\n", info_log); glDeleteProgram(program); glDeleteShader(fragment_shader); glDeleteShader(vertex_shader); program = 0u; } } } else { fprintf(stderr, "ERROR: Unable to load fragment shader\n"); glDeleteShader(vertex_shader); } } else { fprintf(stderr, "ERROR: Unable to load vertex shader\n"); } glDeleteShader(fragment_shader); glDeleteShader(vertex_shader); return program; }
bool Shader::Init(const string& vertexShaderFile, const string& fragmentShaderFile) { GLuint vertexShader = MakeShader(GL_VERTEX_SHADER, vertexShaderFile); if (!vertexShader) return false; GLuint fragmentShader = MakeShader(GL_FRAGMENT_SHADER, fragmentShaderFile); if (!fragmentShader) return false; program = MakeProgram(vertexShader, fragmentShader); if (!program) return false; glDeleteShader(vertexShader); glDeleteShader(fragmentShader); return true; }
static void LoadShader() { GLuint techID = MakeShader("content/shader.vsh", "content/shader.fsh"); Shader = malloc(sizeof(ColorShader)); GLuint error = glGetError(); if (error>0) { __android_log_print(ANDROID_LOG_INFO, "NATIVE", "MAKESHADER ERROR %i", error); assert(error==0); } GetTech(techID, Shader); error = glGetError(); if (error>0) { __android_log_print(ANDROID_LOG_INFO, "NATIVE", "GET TECH ERROR %i", error); assert(error==0); } }