Beispiel #1
0
static GLuint _shader_compile(const char *aSrc, GLenum aType, bool *aoSucceeded)
{
    GLuint shaderObject;

    GLchar **source = malloc(sizeof(GLchar*));
    source[0] = (GLchar*)aSrc;
    if(!source) {
        *aoSucceeded = false;
        free(source);
        return 0;
    }

    shaderObject = glCreateShader(aType);
    glShaderSource(shaderObject, 1, (const GLchar **)source, NULL);
    glCompileShader(shaderObject);

    GLint temp;
    glGetShaderiv(shaderObject, GL_INFO_LOG_LENGTH, &temp);
    if(temp > 0) {
        GLchar *log = (GLchar *)malloc(temp);
        glGetShaderInfoLog(shaderObject, temp, &temp, log);
        dynamo_log(">> %s shader compile log:\n %s\n", aType == GL_FRAGMENT_SHADER ? "Fragment" : "Vertex", log);
        free(log);
    }

    glGetShaderiv(shaderObject, GL_COMPILE_STATUS, &temp);
    if(temp == GL_FALSE) {
        *aoSucceeded = false;
        dynamo_log(">> Failed to compile shader:\n%s\n---", aSrc);
    }
    *aoSucceeded = true;
    free(source);

    return shaderObject;
}
Beispiel #2
0
bool luaCtx_pcall(LuaContext_t *aCtx, int nargs, int nresults, int errfunc)
{
    int err = lua_pcall(aCtx->luaState, nargs, nresults, errfunc);
    if(err) {
        dynamo_log("Lua error: %s", (char*)lua_tostring(aCtx->luaState, -1));
        lua_pop(aCtx->luaState, 1);
        return false;
    }
    return true;
}
Beispiel #3
0
static bool _shader_link(GLuint aProgramObject)
{
    glLinkProgram(aProgramObject);

    GLint logLength;
    glGetProgramiv(aProgramObject, GL_INFO_LOG_LENGTH, &logLength);
    if(logLength > 0) {
        GLchar *log = (GLchar *)malloc(logLength);
        glGetProgramInfoLog(aProgramObject, logLength, &logLength, log);
        dynamo_log(">> Program link log:\n%s", log);
        free(log);
    }
    
    bool success;
    glGetProgramiv(aProgramObject, GL_LINK_STATUS, (GLint *)&success);
    if(success == false)
        dynamo_log("Failed to link shader program");
    return success;
}
Beispiel #4
0
bool luaCtx_executeString(LuaContext_t *aCtx, const char *aScript)
{
    int err = 0;
    err = luaL_loadstring(aCtx->luaState, aScript);
    if(err) {
        dynamo_log("Lua error: %s", (char*)lua_tostring(aCtx->luaState, -1));
        lua_pop(aCtx->luaState, 1);
        return false;
    }
    return luaCtx_pcall(aCtx, 0, 0, 0);
}
Beispiel #5
0
void worldConstr_setAnchorB(WorldConstraint_t *aConstraint, vec2_t aAnchor)
{
    switch(aConstraint->type) {
    case kWorldJointType_Pin:
        cpPinJointSetAnchr2(aConstraint->cpConstraint, VEC2_TO_CPV(aAnchor));
        break;
    case kWorldJointType_Slide:
        cpSlideJointSetAnchr2(aConstraint->cpConstraint, VEC2_TO_CPV(aAnchor));
        break;
    case kWorldJointType_DampedSpring:
        cpDampedSpringSetAnchr2(aConstraint->cpConstraint, VEC2_TO_CPV(aAnchor));
        break;
    default:
        dynamo_log("Invalid constraint");
    }
}
Beispiel #6
0
vec2_t worldConstr_anchorB(WorldConstraint_t *aConstraint)
{
    cpVect ret;
    switch(aConstraint->type) {
    case kWorldJointType_Pin:
        ret = cpPinJointGetAnchr2(aConstraint->cpConstraint);
        break;
    case kWorldJointType_Slide:
        ret = cpSlideJointGetAnchr2(aConstraint->cpConstraint);
        break;
    case kWorldJointType_DampedSpring:
        ret = cpDampedSpringGetAnchr2(aConstraint->cpConstraint);
        break;
    default:
        dynamo_log("Invalid constraint");
        ret = cpv(-1,-1);
    }
    return CPV_TO_VEC2(ret);
}
Beispiel #7
0
Texture_t *texture_loadFromPng(const char *aPath, bool aRepeatHorizontal, bool aRepeatVertical)
{
    Texture_t *out = obj_create_autoreleased(&Class_Texture);
    out->displayCallback = (RenderableDisplayCallback_t)&_texture_draw;
    
    Png_t *png = png_load(aPath);
    if(!png) {
        dynamo_log("Unable to load png file from %s", aPath);
        return NULL;
    }
    
    glGenTextures(1, &out->id);
    glBindTexture(GL_TEXTURE_2D, out->id);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    
    glTexImage2D(GL_TEXTURE_2D, 0, png->hasAlpha ? GL_RGBA : GL_RGB, png->width, png->height,
                 0, png->hasAlpha ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, png->data);
    glError()
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, aRepeatHorizontal ? GL_REPEAT : GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, aRepeatVertical   ? GL_REPEAT : GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    // Mipmaps can only be generated if the texture size is a power of 2
    if(_isPowerOfTwo(png->width) && _isPowerOfTwo(png->height) && !aRepeatHorizontal && !aRepeatVertical) {
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
        glGenerateMipmap(GL_TEXTURE_2D);
    } else {
            dynamo_assert(!( (!_isPowerOfTwo(png->width) || !_isPowerOfTwo(png->height))
                              && (aRepeatHorizontal || aRepeatVertical) ),
                          "Repeating textures must have power of 2 dimensions");
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    }
    glError()
    
    out->size = vec2_create(png->width, png->height);
    out->pxAlignInset = vec2_create(
                                    (1.0f/out->size.w) * 0.5,
                                    (1.0f/out->size.h) * 0.5
                                    );
    
    return out;
}
Beispiel #8
0
void obj_zombie_error(Obj_t *aObj)
{
    _Obj_guts *guts = aObj;
    dynamo_log("*** TRIED TO FREE ZOMBIE OBJECT (%p). Break on obj_zombie_error to debug", guts);
    _print_trace();
}