Skip to content

Instantly share code, notes, and snippets.

@rdb
Last active January 31, 2019 10:36
Show Gist options
  • Save rdb/83b1d952e3808f100465 to your computer and use it in GitHub Desktop.
Save rdb/83b1d952e3808f100465 to your computer and use it in GitHub Desktop.
// clang -O3 gl-preferred-format.c -o gl-preferred-format -lGL -lglut
#include <stdio.h>
#define GL_GLEXT_PROTOTYPES
#if defined(__GNUC__) && (defined(__APPLE_CPP__) || defined(__APPLE_CC__))
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_ALPHA);
int win = glutCreateWindow(argv[0]);
const GLubyte *name = glGetString(GL_VENDOR);
const GLubyte *renderer = glGetString(GL_RENDERER);
const GLubyte *version = glGetString(GL_VERSION);
printf("Vendor: %s\nRenderer: %s\nVersion: %s\n", name, renderer, version);
printf("Preferred formats for GL_RGB8:\n");
GLint preferred_format, preferred_type;
glGetInternalformativ(GL_TEXTURE_2D, GL_RGB8, GL_TEXTURE_IMAGE_FORMAT, 1, &preferred_format);
glGetInternalformativ(GL_TEXTURE_2D, GL_RGB8, GL_TEXTURE_IMAGE_TYPE, 1, &preferred_type);
printf(" 0x%x / 0x%x -- upload\n", preferred_format, preferred_type);
glGetInternalformativ(GL_TEXTURE_2D, GL_RGB8, GL_READ_PIXELS_FORMAT, 1, &preferred_format);
glGetInternalformativ(GL_TEXTURE_2D, GL_RGB8, GL_READ_PIXELS_TYPE, 1, &preferred_type);
printf(" 0x%x / 0x%x -- read\n", preferred_format, preferred_type);
glGetInternalformativ(GL_TEXTURE_2D, GL_RGB8, GL_GET_TEXTURE_IMAGE_FORMAT, 1, &preferred_format);
glGetInternalformativ(GL_TEXTURE_2D, GL_RGB8, GL_GET_TEXTURE_IMAGE_TYPE, 1, &preferred_type);
printf(" 0x%x / 0x%x -- get texture\n", preferred_format, preferred_type);
printf("Preferred formats for GL_RGBA8:\n");
glGetInternalformativ(GL_TEXTURE_2D, GL_RGBA8, GL_TEXTURE_IMAGE_FORMAT, 1, &preferred_format);
glGetInternalformativ(GL_TEXTURE_2D, GL_RGBA8, GL_TEXTURE_IMAGE_TYPE, 1, &preferred_type);
printf(" 0x%x / 0x%x -- upload\n", preferred_format, preferred_type);
glGetInternalformativ(GL_TEXTURE_2D, GL_RGBA8, GL_READ_PIXELS_FORMAT, 1, &preferred_format);
glGetInternalformativ(GL_TEXTURE_2D, GL_RGBA8, GL_READ_PIXELS_TYPE, 1, &preferred_type);
printf(" 0x%x / 0x%x -- read\n", preferred_format, preferred_type);
glGetInternalformativ(GL_TEXTURE_2D, GL_RGBA8, GL_GET_TEXTURE_IMAGE_FORMAT, 1, &preferred_format);
glGetInternalformativ(GL_TEXTURE_2D, GL_RGBA8, GL_GET_TEXTURE_IMAGE_TYPE, 1, &preferred_type);
printf(" 0x%x / 0x%x -- get texture\n", preferred_format, preferred_type);
glutDestroyWindow(win);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment