Example usage for org.lwjgl.opengl GL11 glGetError

List of usage examples for org.lwjgl.opengl GL11 glGetError

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 glGetError.

Prototype

@NativeType("GLenum")
public static int glGetError() 

Source Link

Document

Returns error information.

Usage

From source file:mwisbest.openbase.opengl.TextureLoader.java

License:Open Source License

/**
 * Get a texture from a image file//from  w ww  .ja  v a2 s . c om
 * 
 * @param in The stream from which we can load the image
 * @param resourceName The name to give this image in the internal cache
 * @param flipped True if we should flip the image on the y-axis while loading
 * @param filter The filter to use when scaling the texture
 * @param transparent The colour to interpret as transparent or null if none
 * @return The texture loaded
 * @throws IOException Indicates a failure to load the image
 */
public TextureImplementation getTexture(InputStream in, String resourceName, boolean flipped, int filter,
        int[] transparent) throws IOException {
    HashMap<String, Object> hash = this.texturesLinear;
    if (filter == GL11.GL_NEAREST)
        hash = this.texturesNearest;

    String resName = resourceName;
    if (transparent != null)
        resName += ":" + transparent[0] + ":" + transparent[1] + ":" + transparent[2];
    resName += ":" + flipped;

    @SuppressWarnings("unchecked")
    SoftReference<TextureImplementation> ref = (SoftReference<TextureImplementation>) hash.get(resName);
    if (ref != null) {
        TextureImplementation tex = ref.get();
        if (tex != null)
            return tex;
        hash.remove(resName);
    }

    // horrible test until I can find something more suitable
    try {
        GL11.glGetError();
    } catch (NullPointerException e) {
        throw new RuntimeException(
                "Image based resources must be loaded as part of init() or the game loop. They cannot be loaded before initialisation.");
    }

    TextureImplementation tex = this.getTexture(in, resourceName, GL11.GL_TEXTURE_2D, filter, filter, flipped,
            transparent);

    hash.put(resName, new SoftReference<>(tex));

    return tex;
}

From source file:net.betabears.the2dlibrary.graphics.shader.Shader.java

public void createShader() {
    id = GL20.glCreateShader(type);/*from   ww  w .j a v a  2s .c  om*/
    GL20.glShaderSource(id, text);
    GL20.glCompileShader(id);

    int i;
    while ((i = GL11.glGetError()) != 0) {
        LOGGER.log(Level.WARNING, "Error happened during creation of ShaderProgram. GL error code: {0}", i);
    }
}

From source file:net.betabears.the2dlibrary.graphics.shader.ShaderProgram.java

@Override
public void init() {
    if (isLoaded && !isInited) {
        s0.createShader();//from   ww  w  .  j  av  a  2  s. co m
        s1.createShader();

        id = GL20.glCreateProgram();
        GL20.glAttachShader(id, s0.getID());
        GL20.glAttachShader(id, s1.getID());
        GL20.glLinkProgram(id);
        GL20.glValidateProgram(id);

        int i;
        while ((i = GL11.glGetError()) != 0) {
            LOGGER.log(Level.WARNING, "Error happened during creation of ShaderProgram. GL error code: {0}", i);
        }
        isInited = true;
    } else {
        LOGGER.log(Level.WARNING, "load() wasn't called before init() or init() has been called already.");
    }
}

From source file:net.kubin.rendering.ChunkMeshBuilder.java

License:Apache License

public static void generateChunkMesh(Chunk chunk, MeshType meshType) {
    if (DEBUG) {/* ww w .  jav  a2 s  .  c  o  m*/
        System.out.println("Building " + meshType.name() + " Mesh for " + chunk.toString() + "...");
    }

    /* Make sure there are no list edits anymore */
    chunk.performListChanges();

    ChunkMesh mesh = chunk.getMesh();
    mesh.destroy(meshType);

    /* Compute vertex count */
    int vertexCount = chunk.getVertexCount(meshType);

    if (DEBUG) {
        System.out.println("\tVertex Count = " + vertexCount);
    }

    /*
     * If there are no faces visible yet (because of generating busy), don't
     * create a buffer
     */
    if (vertexCount == 0) {
        return;
    }

    mesh.setVertexCount(meshType, vertexCount);

    /* Create a buffer */
    int vbo = BufferManager.getInstance().createBuffer();
    mesh.setVBO(meshType, vbo);

    /* Bind the buffer */
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);

    /* Allocate size for the buffer */
    int size = vertexCount * STRIDE * FLOAT_SIZE;
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, size, GL15.GL_STATIC_DRAW);

    if (DEBUG) {
        System.out.println(
                "\tCreate VBO: " + vbo + " with size = " + size + " (ERROR: " + GL11.glGetError() + ")");
    }

    /* Get the native buffer to write to */
    ByteBuffer byteBuffer = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY, size, null);

    if (byteBuffer == null) {
        System.out.println("\tCouldn't create a native VBO!: GL Error Code = " + GL11.glGetError());

        GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

        mesh.destroy(meshType);
        Thread.dumpStack();
        mesh.setVBO(meshType, -1);
        mesh.setVertexCount(meshType, 0);

        return;
    }

    FloatBuffer vertexBuffer = byteBuffer.asFloatBuffer();

    /* Store all vertices in the buffer */
    USED_SIZE = 0;

    /* Local temporary variables, used to speed up */
    IntList blockList = chunk.getVisibleBlocks();
    int blockIndex = -1;
    byte BlockDef = 0;
    boolean special = false;
    Vec3i vec = new Vec3i();
    BlockDef type;
    Block block = null;
    LightBuffer lightBuffer = chunk.getLightBuffer();
    byte faceMask = 0;

    /* Iterate over the blocks */
    for (int i = 0; i < blockList.size(); ++i) {
        blockIndex = blockList.get(i);
        BlockDef = chunk.getChunkData().getBlockDef(blockIndex);

        if (BlockDef == 0) {
            continue;
        }

        special = chunk.getChunkData().isSpecial(blockIndex);
        type = _blockManager.getBlockDef(BlockDef);

        if ((meshType == MeshType.OPAQUE && !type.isTranslucent() && type.hasNormalAABB())
                || (meshType == MeshType.TRANSLUCENT && (type.isTranslucent() || !type.hasNormalAABB()))) {

            ChunkData.indexToPosition(blockIndex, vec);

            /* Build the light buffer */
            vec.setX(vec.x() + chunk.getAbsoluteX());
            vec.setZ(vec.z() + chunk.getAbsoluteZ());

            lightBuffer.setReferencePoint(vec.x(), vec.y(), vec.z());

            if (special) {
                block = chunk.getChunkData().getSpecialBlock(blockIndex);

                if (block.isVisible()) {
                    block.storeInVBO(vertexBuffer, lightBuffer);
                }
            } else {
                faceMask = chunk.getChunkData().getFaceMask(blockIndex);
                type.getDefaultBlockBrush().setFaceMask(faceMask);
                type.getBrush().storeInVBO(vertexBuffer, vec.x() + 0.5f, vec.y() + 0.5f, vec.z() + 0.5f,
                        lightBuffer);

            }
        }
    }

    /* Perform a check */
    if (USED_SIZE != STRIDE * FLOAT_SIZE * mesh.getVertexCount(meshType)) {
        System.out.println("\t[WARNING!]: Used size = " + USED_SIZE);
        System.out.println("\t[WARNING!]: Vertex count = " + USED_SIZE / STRIDE / FLOAT_SIZE);
        mesh.setVertexCount(meshType, USED_SIZE / STRIDE / FLOAT_SIZE);
    }

    byteBuffer.flip();

    GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

}

From source file:net.smert.frameworkgl.opengl.OpenGL1.java

License:Apache License

public int getError() {
    return GL11.glGetError();
}

From source file:org.bonsaimind.badgersvoyage.tools.planetstudio.ErrorChecker.java

License:Open Source License

public static void exitOnOpenGlError(String message) {
    int error = GL11.glGetError();

    if (error != GL11.GL_NO_ERROR) {
        System.err.println(message);
        System.err.println(GLU.gluErrorString(error));
        System.exit(-1);// w  w  w . ja va 2  s.c  o m
    }
}

From source file:org.craftmania.rendering.ChunkMeshBuilder.java

License:Apache License

public static void generateChunkMesh(Chunk chunk, MeshType meshType) {
    if (DEBUG)//from w w w .  java2s  .c o m
        System.out.println("Building " + meshType.name() + " Mesh for " + chunk.toString() + "...");

    /* Make sure there are no list edits anymore */
    chunk.performListChanges();

    ChunkMesh mesh = chunk.getMesh();
    mesh.destroy(meshType);

    /* Compute vertex count */
    int vertexCount = chunk.getVertexCount(meshType);
    if (DEBUG)
        System.out.println("\tVertex Count = " + vertexCount);
    /*
     * If there are no faces visible yet (because of generating busy), don't
     * create a buffer
     */
    if (vertexCount == 0) {
        return;
    }
    mesh.setVertexCount(meshType, vertexCount);

    /* Create a buffer */
    int vbo = BufferManager.getInstance().createBuffer();
    mesh.setVBO(meshType, vbo);

    /* Bind the buffer */
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);

    /* Allocate size for the buffer */
    int size = vertexCount * STRIDE * FLOAT_SIZE;
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, size, GL15.GL_STATIC_DRAW);

    if (DEBUG)
        System.out.println(
                "\tCreate VBO: " + vbo + " with size = " + size + " (ERROR: " + GL11.glGetError() + ")");

    /* Get the native buffer to write to */
    ByteBuffer byteBuffer = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY, size, null);
    if (byteBuffer == null) {
        System.out.println("\tCouldn't create a native VBO!: GL Error Code = " + GL11.glGetError());

        GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

        mesh.destroy(meshType);
        Thread.dumpStack();
        mesh.setVBO(meshType, -1);
        mesh.setVertexCount(meshType, 0);

        return;
    }

    FloatBuffer vertexBuffer = byteBuffer.asFloatBuffer();

    /* Store all vertices in the buffer */
    USED_SIZE = 0;

    /* Local temporary variables, used to speed up */
    IntList blockList = chunk.getVisibleBlocks();
    int blockIndex = -1;
    byte blockType = 0;
    boolean special = false;
    Vec3i vec = new Vec3i();
    BlockType type;
    Block block = null;
    LightBuffer lightBuffer = chunk.getLightBuffer();
    byte faceMask = 0;

    /* Iterate over the blocks */
    for (int i = 0; i < blockList.size(); ++i) {
        blockIndex = blockList.get(i);
        blockType = chunk.getChunkData().getBlockType(blockIndex);
        if (blockType == 0)
            continue;
        special = chunk.getChunkData().isSpecial(blockIndex);
        type = _blockManager.getBlockType(blockType);

        if ((meshType == MeshType.OPAQUE && !type.isTranslucent() && type.hasNormalAABB())
                || (meshType == MeshType.TRANSLUCENT && (type.isTranslucent() || !type.hasNormalAABB()))) {

            ChunkData.indexToPosition(blockIndex, vec);

            /* Build the light buffer */

            vec.setX(vec.x() + chunk.getAbsoluteX());
            vec.setZ(vec.z() + chunk.getAbsoluteZ());

            lightBuffer.setReferencePoint(vec.x(), vec.y(), vec.z());

            if (special) {
                block = chunk.getChunkData().getSpecialBlock(blockIndex);
                if (block.isVisible()) {
                    block.storeInVBO(vertexBuffer, lightBuffer);
                }
            } else {
                if (type.isCrossed()) {
                    type.getCrossedBlockBrush().storeInVBO(vertexBuffer, vec.x() + 0.5f, vec.y() + 0.5f,
                            vec.z() + 0.5f, lightBuffer);
                } else {
                    faceMask = chunk.getChunkData().getFaceMask(blockIndex);
                    type.getDefaultBlockBrush().setFaceMask(faceMask);
                    type.getBrush().storeInVBO(vertexBuffer, vec.x() + 0.5f, vec.y() + 0.5f, vec.z() + 0.5f,
                            lightBuffer);
                }
            }
        }
    }

    /* Perform a check */
    if (USED_SIZE != STRIDE * FLOAT_SIZE * mesh.getVertexCount(meshType)) {
        System.out.println("\t[WARNING!]: Used size = " + USED_SIZE);
        System.out.println("\t[WARNING!]: Vertex count = " + USED_SIZE / STRIDE / FLOAT_SIZE);
        mesh.setVertexCount(meshType, USED_SIZE / STRIDE / FLOAT_SIZE);
    }

    byteBuffer.flip();

    GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

}

From source file:org.free.jake2.render.lwjgl.Main.java

License:Open Source License

/**
 * R_Init2//w  w  w.  jav a  2s.co m
 */
protected boolean R_Init2() {
    VID.MenuInit();

    /*
     ** get our various GL strings
     */
    gl_config.vendor_string = GL11.glGetString(GL11.GL_VENDOR);
    VID.Printf(Defines.PRINT_ALL, "GL_VENDOR: " + gl_config.vendor_string + '\n');
    gl_config.renderer_string = GL11.glGetString(GL11.GL_RENDERER);
    VID.Printf(Defines.PRINT_ALL, "GL_RENDERER: " + gl_config.renderer_string + '\n');
    gl_config.version_string = GL11.glGetString(GL11.GL_VERSION);
    VID.Printf(Defines.PRINT_ALL, "GL_VERSION: " + gl_config.version_string + '\n');
    gl_config.extensions_string = GL11.glGetString(GL11.GL_EXTENSIONS);
    VID.Printf(Defines.PRINT_ALL, "GL_EXTENSIONS: " + gl_config.extensions_string + '\n');

    gl_config.parseOpenGLVersion();

    String renderer_buffer = gl_config.renderer_string.toLowerCase();
    String vendor_buffer = gl_config.vendor_string.toLowerCase();

    if (renderer_buffer.indexOf("voodoo") >= 0) {
        if (renderer_buffer.indexOf("rush") < 0) {
            gl_config.renderer = GL_RENDERER_VOODOO;
        } else {
            gl_config.renderer = GL_RENDERER_VOODOO_RUSH;
        }
    } else if (vendor_buffer.indexOf("sgi") >= 0) {
        gl_config.renderer = GL_RENDERER_SGI;
    } else if (renderer_buffer.indexOf("permedia") >= 0) {
        gl_config.renderer = GL_RENDERER_PERMEDIA2;
    } else if (renderer_buffer.indexOf("glint") >= 0) {
        gl_config.renderer = GL_RENDERER_GLINT_MX;
    } else if (renderer_buffer.indexOf("glzicd") >= 0) {
        gl_config.renderer = GL_RENDERER_REALIZM;
    } else if (renderer_buffer.indexOf("gdi") >= 0) {
        gl_config.renderer = GL_RENDERER_MCD;
    } else if (renderer_buffer.indexOf("pcx2") >= 0) {
        gl_config.renderer = GL_RENDERER_PCX2;
    } else if (renderer_buffer.indexOf("verite") >= 0) {
        gl_config.renderer = GL_RENDERER_RENDITION;
    } else {
        gl_config.renderer = GL_RENDERER_OTHER;
    }

    String monolightmap = gl_monolightmap.string.toUpperCase();
    if (monolightmap.length() < 2 || monolightmap.charAt(1) != 'F') {
        if (gl_config.renderer == GL_RENDERER_PERMEDIA2) {
            Cvar.Set("gl_monolightmap", "A");
            VID.Printf(Defines.PRINT_ALL, "...using gl_monolightmap 'a'\n");
        } else if ((gl_config.renderer & GL_RENDERER_POWERVR) != 0) {
            Cvar.Set("gl_monolightmap", "0");
        } else {
            Cvar.Set("gl_monolightmap", "0");
        }
    }

    // power vr can't have anything stay in the framebuffer, so
    // the screen needs to redraw the tiled background every frame
    if ((gl_config.renderer & GL_RENDERER_POWERVR) != 0) {
        Cvar.Set("scr_drawall", "1");
    } else {
        Cvar.Set("scr_drawall", "0");
    }

    // MCD has buffering issues
    if (gl_config.renderer == GL_RENDERER_MCD) {
        Cvar.SetValue("gl_finish", 1);
    }

    if ((gl_config.renderer & GL_RENDERER_3DLABS) != 0) {
        if (gl_3dlabs_broken.value != 0.0f) {
            gl_config.allow_cds = false;
        } else {
            gl_config.allow_cds = true;
        }
    } else {
        gl_config.allow_cds = true;
    }

    if (gl_config.allow_cds) {
        VID.Printf(Defines.PRINT_ALL, "...allowing CDS\n");
    } else {
        VID.Printf(Defines.PRINT_ALL, "...disabling CDS\n");
    }

    /*
     ** grab extensions
     */
    if (gl_config.extensions_string.indexOf("GL_EXT_compiled_vertex_array") >= 0
            || gl_config.extensions_string.indexOf("GL_SGI_compiled_vertex_array") >= 0) {
        VID.Printf(Defines.PRINT_ALL, "...enabling GL_EXT_compiled_vertex_array\n");
        //       qglLockArraysEXT = ( void * ) qwglGetProcAddress( "glLockArraysEXT" );
        if (gl_ext_compiled_vertex_array.value != 0.0f) {
            qglLockArraysEXT = true;
        } else {
            qglLockArraysEXT = false;
        }
        //       qglUnlockArraysEXT = ( void * ) qwglGetProcAddress( "glUnlockArraysEXT" );
        //qglUnlockArraysEXT = true;
    } else {
        VID.Printf(Defines.PRINT_ALL, "...GL_EXT_compiled_vertex_array not found\n");
        qglLockArraysEXT = false;
    }

    if (gl_config.extensions_string.indexOf("WGL_EXT_swap_control") >= 0) {
        qwglSwapIntervalEXT = true;
        VID.Printf(Defines.PRINT_ALL, "...enabling WGL_EXT_swap_control\n");
    } else {
        qwglSwapIntervalEXT = false;
        VID.Printf(Defines.PRINT_ALL, "...WGL_EXT_swap_control not found\n");
    }

    if (gl_config.extensions_string.indexOf("GL_EXT_point_parameters") >= 0) {
        if (gl_ext_pointparameters.value != 0.0f) {
            //          qglPointParameterfEXT = ( void (APIENTRY *)( GLenum, GLfloat ) ) qwglGetProcAddress( "glPointParameterfEXT" );
            qglPointParameterfEXT = true;
            //          qglPointParameterfvEXT = ( void (APIENTRY *)( GLenum, const GLfloat * ) ) qwglGetProcAddress( "glPointParameterfvEXT" );
            VID.Printf(Defines.PRINT_ALL, "...using GL_EXT_point_parameters\n");
        } else {
            VID.Printf(Defines.PRINT_ALL, "...ignoring GL_EXT_point_parameters\n");
        }
    } else {
        VID.Printf(Defines.PRINT_ALL, "...GL_EXT_point_parameters not found\n");
    }

    // #ifdef __linux__
    //    if ( strstr( gl_config.extensions_string, "3DFX_set_global_palette" ))
    //    {
    //       if ( gl_ext_palettedtexture->value )
    //       {
    //          VID.Printf( Defines.PRINT_ALL, "...using 3DFX_set_global_palette\n" );
    //          qgl3DfxSetPaletteEXT = ( void ( APIENTRY * ) (GLuint *) )qwglGetProcAddress( "gl3DfxSetPaletteEXT" );
    ////          qglColorTableEXT = Fake_glColorTableEXT;
    //       }
    //       else
    //       {
    //          VID.Printf( Defines.PRINT_ALL, "...ignoring 3DFX_set_global_palette\n" );
    //       }
    //    }
    //    else
    //    {
    //       VID.Printf( Defines.PRINT_ALL, "...3DFX_set_global_palette not found\n" );
    //    }
    // #endif

    if (!qglColorTableEXT && gl_config.extensions_string.indexOf("GL_EXT_paletted_texture") >= 0
            && gl_config.extensions_string.indexOf("GL_EXT_shared_texture_palette") >= 0) {
        if (gl_ext_palettedtexture.value != 0.0f) {
            VID.Printf(Defines.PRINT_ALL, "...using GL_EXT_shared_texture_palette\n");
            qglColorTableEXT = false; // true; TODO jogl bug
        } else {
            VID.Printf(Defines.PRINT_ALL, "...ignoring GL_EXT_shared_texture_palette\n");
            qglColorTableEXT = false;
        }
    } else {
        VID.Printf(Defines.PRINT_ALL, "...GL_EXT_shared_texture_palette not found\n");
    }

    if (gl_config.extensions_string.indexOf("GL_ARB_multitexture") >= 0) {
        VID.Printf(Defines.PRINT_ALL, "...using GL_ARB_multitexture\n");
        qglActiveTextureARB = true;
        GL_TEXTURE0 = ARBMultitexture.GL_TEXTURE0_ARB;
        GL_TEXTURE1 = ARBMultitexture.GL_TEXTURE1_ARB;
    } else {
        VID.Printf(Defines.PRINT_ALL, "...GL_ARB_multitexture not found\n");
    }

    if (!(qglActiveTextureARB)) {
        return false;
    }

    GL_SetDefaultState();

    GL_InitImages();
    Mod_Init();
    R_InitParticleTexture();
    Draw_InitLocal();

    int err = GL11.glGetError();
    if (err != GL11.GL_NO_ERROR) {
        VID.Printf(Defines.PRINT_ALL, "glGetError() = 0x%x\n\t%s\n",
                new Vargs(2).add(err).add("" + GL11.glGetString(err)));
    }

    return true;
}

From source file:org.jogamp.glg2d.GLG2DUtils.java

License:Apache License

public static void logGLError() {
    int error = GL11.glGetError();
    if (error != GL11.GL_NO_ERROR) {
        LOGGER.log(Level.SEVERE, "GL Error: code " + error);
    }// w  w  w .jav a  2 s .  co m
}

From source file:org.jogamp.glg2d.impl.shader.AbstractShaderPipeline.java

License:Apache License

protected int compileShader(int type, ByteBuffer src) throws ShaderException {
    int id = GL20.glCreateShader(type);

    GL20.glShaderSource(id, src);//from  w w w.  j a  v a 2 s  .c om
    int err = GL11.glGetError();
    if (err != GL11.GL_NO_ERROR) {
        throw new ShaderException("Shader source failed, GL Error: 0x" + Integer.toHexString(err));
    }

    GL20.glCompileShader(id);
    err = GL11.glGetError();
    if (err != GL11.GL_NO_ERROR) {
        throw new ShaderException("Compile failed, GL Error: 0x" + Integer.toHexString(err));
    }

    return id;
}