本文整理汇总了C++中GLTexture::setImage方法的典型用法代码示例。如果您正苦于以下问题:C++ GLTexture::setImage方法的具体用法?C++ GLTexture::setImage怎么用?C++ GLTexture::setImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLTexture
的用法示例。
在下文中一共展示了GLTexture::setImage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Target_init
void Target_init() {
JSONDeserializationContext * context;
GLTexture * texture;
BitmapImage * image;
context = JSONDeserializationContext_createWithFile(resourcePath("test_font.json"));
if (context->status != SERIALIZATION_ERROR_OK) {
fprintf(stderr, "Fatal error: Couldn't load test_font.json (status %d)\n", context->status);
exit(EXIT_FAILURE);
}
font = GLBitmapFont_deserialize((DeserializationContext *) context);
context->dispose(context);
if (font == NULL) {
fprintf(stderr, "Fatal error: Couldn't deserialize test_font.json (status %d)\n", context->status);
exit(EXIT_FAILURE);
}
context = JSONDeserializationContext_createWithFile(resourcePath(font->textureName));
if (context->status != SERIALIZATION_ERROR_OK) {
fprintf(stderr, "Fatal error: Couldn't load %s (status %d)\n", font->textureName, context->status);
exit(EXIT_FAILURE);
}
texture = GLTexture_deserialize((DeserializationContext *) context);
context->dispose(context);
if (texture == NULL) {
fprintf(stderr, "Fatal error: Couldn't deserialize %s (status %d)\n", font->textureName, context->status);
exit(EXIT_FAILURE);
}
image = PNGImageIO_loadPNGFile(resourcePath(texture->imageName), PNG_PIXEL_FORMAT_AUTOMATIC, true);
if (image == NULL) {
fprintf(stderr, "Fatal error: Couldn't load %s\n", texture->imageName);
exit(EXIT_FAILURE);
}
texture->setImage(texture, 0, image->width, image->height, image->bytesPerRow, image->pixels);
image->dispose(image);
font->setTexture(font, texture, true);
memset(freeformText, 0, FREEFORM_LENGTH_MAX + 1);
if (GLGraphics_getOpenGLAPIVersion() == GL_API_VERSION_ES2) {
void * fileContents;
size_t fileLength;
GLint shaderLength;
GLuint vertexShader, fragmentShader;
GLuint shaderProgram;
GLint logLength;
shaderProgram = glCreateProgram();
vertexShader = glCreateShader(GL_VERTEX_SHADER);
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
fileContents = readFileSimple(resourcePath("basic.vert"), &fileLength);
shaderLength = fileLength;
glShaderSource(vertexShader, 1, (const GLchar **) &fileContents, &shaderLength);
free(fileContents);
fileContents = readFileSimple(resourcePath("basic.frag"), &fileLength);
shaderLength = fileLength;
glShaderSource(fragmentShader, 1, (const GLchar **) &fileContents, &shaderLength);
free(fileContents);
glCompileShader(vertexShader);
glCompileShader(fragmentShader);
glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0) {
GLchar * log = malloc(logLength);
glGetShaderInfoLog(vertexShader, logLength, &logLength, log);
fprintf(stderr, "Vertex shader compile log:\n%s\n", log);
free(log);
}
glGetShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0) {
GLchar * log = malloc(logLength);
glGetShaderInfoLog(fragmentShader, logLength, &logLength, log);
fprintf(stderr, "Fragment shader compile log:\n%s\n", log);
free(log);
}
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glBindAttribLocation(shaderProgram, 0, "vertexPositionAttrib");
glBindAttribLocation(shaderProgram, 1, "vertexTexCoordAttrib");
glBindAttribLocation(shaderProgram, 2, "vertexColorAttrib");
glLinkProgram(shaderProgram);
glGetProgramiv(shaderProgram, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0) {
GLchar * log = malloc(logLength);
glGetProgramInfoLog(shaderProgram, logLength, &logLength, log);
fprintf(stderr, "Program link log:\n%s\n", log);
free(log);
}
glValidateProgram(shaderProgram);
glGetProgramiv(shaderProgram, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0) {
GLchar * log = malloc(logLength);
glGetProgramInfoLog(shaderProgram, logLength, &logLength, log);
fprintf(stderr, "Program validation log:\n%s\n", log);
free(log);
}
matrixUniform = glGetUniformLocation(shaderProgram, "matrix");
textureUniform = glGetUniformLocation(shaderProgram, "texture");
glDeleteShader(vertexShader);
//.........这里部分代码省略.........