void oglInit(int width, int height) { start_func oglError("oglInit: selectVideoMode"); oglDebug(glViewport(0, 0, width, height)); oglDebug(glClearColor(0.0f, 0.0f, 0.0f, 0.0f)); oglDebug(glEnable(GL_TEXTURE_2D)); oglDebug(glDisable(GL_DEPTH_TEST)); oglDebug(glAlphaFunc(GL_GREATER, 0)); oglDebug(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); oglDebug(glDisable(GL_ALPHA_TEST)); oglDebug(glDisable(GL_BLEND)); alphaOn = 0; blendOn = 0; // May change later oglDebug(glShadeModel(GL_SMOOTH)); // Change to modulate to allow coloring oglDebug(glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)); oglDebug(glMatrixMode(GL_PROJECTION)); oglDebug(glLoadIdentity()); oglDebug(glOrtho(0, width, height, 0, 0, 1)); oglDebug(glMatrixMode(GL_MODELVIEW)); oglError("oglInit"); // Some places optimize output and need to reset when GL is initialized TextureMap::setupOptimizations(); }
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; }
void programError(GLuint program) { /* prints out detailed compile errors for given program */ #ifdef SHOW_SHADER_ERRORS int infologLength = 0; int charsWritten = 0; GLchar *infoLog; oglError(); glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infologLength); oglError(); if (infologLength > 1) { infoLog = (GLchar *)malloc(infologLength); glGetProgramInfoLog(program, infologLength, &charsWritten, infoLog); printf("Program InfoLog:%s\n", infoLog); free(infoLog); } oglError(); #endif }
void shaderError(GLuint shader) { /* prints out detailed compile errors for the given shader (fragment or vertex) */ #ifdef SHOW_SHADER_ERRORS int infologLength = 0; int charsWritten = 0; GLchar *infoLog; oglError(); glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infologLength); oglError(); if (infologLength > 1) { infoLog = (GLchar *)malloc(infologLength); glGetShaderInfoLog(shader, infologLength, &charsWritten, infoLog); printf("Shader InfoLog:%s\n", infoLog); free(infoLog); } oglError(); #endif }