Jump to content

[1.8.9] [SOLVED] Buggy sphere's or buggy Minecraft GL?


Recommended Posts

Posted

Hi,

 

I'm currently working on rendering a sphere in Minecraft (as a tile entity). But it's not working well.

 

Here are some pics how my sphere looks now:

http://i.imgur.com/JXtNTnJ.png

 

First sphere is totally incorrect drawn, the sphere above doesn't look nice but at least it's a sphere. If I'm farer away both sphere's disappear and when I'm looking from a other

side it looks like there is no sphere. So the sphere is just from ONE side visible.

When I start moving, doesn't matter how much I move all pixels of the sphere begin to move, too. When I stop moving the sphere pixels are still moving around

which really looks horrible. After a few seconds where I don't move the sphere pixels finally stop moving, too and it looks like in the pic above.

 

And here is the code:

@SideOnly(Side.CLIENT)
public class TileEntityPortalRenderer extends TileEntitySpecialRenderer<TileEntityPortal> {
    
    public static int sphereIDOutside;
    public static int sphereIDInside;
    
    @Override
    public void renderTileEntityAt(TileEntityPortal tileEntity, double posX, double posY, double posZ, float partialTicks, int destroyStage) {
        GlStateManager.pushMatrix(); // store the transformation 
        GlStateManager.translate(posX, posY, posZ); // set viewport to tile entity position to render it
        
        /* ============ Rendering Code goes here ============ */
        
        GlStateManager.translate(posX + 1f, posY - .6f, posZ + 1f);
        GlStateManager.enableBlend(); // enable rendering for transparency
        GlStateManager.depthMask(false);
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GlStateManager.color(1.f, 1.f, 1.f, .5f);
        GlStateManager.callList(TileEntityPortalRenderer.sphereIDOutside);
        GlStateManager.callList(TileEntityPortalRenderer.sphereIDInside);
        
        //renderLight(posX, posY, posZ);
        GlStateManager.resetColor();
        GlStateManager.disableBlend();
        
        /* ============ Rendering Code stops here =========== */
        
        GlStateManager.popMatrix(); // restore the transformation, so other renderer's are not messed up
    }
    
    public static void createSphere() {
        Sphere sphere = new Sphere();
        sphere.setDrawStyle(GLU.GLU_FILL); // fill as a solid
        sphere.setNormals(GLU.GLU_SMOOTH); // smooth everything
        
        // First make the call list for the outside of the sphere
        sphere.setOrientation(GLU.GLU_OUTSIDE);
        TileEntityPortalRenderer.sphereIDOutside = GL11.glGenLists(1);
        // Create a new list to hold our sphere data
        GL11.glNewList(TileEntityPortalRenderer.sphereIDOutside, GL11.GL_COMPILE);
        // binds the texture
        ResourceLocation resource = new ResourceLocation(Constants.MOD_ID + ":" + "textures/blocks/sapling_golden.png");
        Minecraft.getMinecraft().getTextureManager().bindTexture(resource);
       
        sphere.draw(1.2f, 32, 32);
        GL11.glEndList();
        
        // Make the call list for the inside of the sphere
        sphere.setOrientation(GLU.GLU_INSIDE);
        TileEntityPortalRenderer.sphereIDInside = GL11.glGenLists(1);
        // Create a new list to hold our sphere data
        GL11.glNewList(TileEntityPortalRenderer.sphereIDInside, GLU.GLU_INSIDE);
        Minecraft.getMinecraft().getTextureManager().bindTexture(resource);
        
        sphere.draw(1.2f, 32, 32);
        GL11.glEndList();
    }
}

 

 @Override
    public void init() {
        super.init();
        
        TileEntityPortalRenderer.createSphere();
    }

 

    @Mod.EventHandler
    public void init(FMLInitializationEvent event) {
        PrimevalForest.proxy.init();
    }

 

Any ideas?

 

Thx in advance.

Bektor

 

Old message:

 

Sometimes you can see just a huge bunch of pixels because not all pixels of the sphere are rendered

and then the sphere is always disappering when you move around or don't have the block with which the

tileentity was placed in the hand. So there is much weird stuff around.

 

    @Override
    public void renderTileEntityAt(TileEntityPortal tileEntity, double posX, double posY, double posZ, float partialTicks, int destroyStage) {
        GlStateManager.pushMatrix(); // store the transformation 
        GlStateManager.translate(posX, posY, posZ); // set viewport to tile entity position to render it
        
        /* ============ Rendering Code goes here ============ */
        
        GlStateManager.translate(posX + 1f, posY - .6f, posZ + 1f);
        GlStateManager.color(1.f, 1.f, 1.f);
        
        Sphere sphere = new Sphere();
        sphere.draw(1.2f, 16, 16);
        GlStateManager.resetColor();
        
        /* ============ Rendering Code stops here =========== */
        
        GlStateManager.popMatrix(); // restore the transformation, so other renderer's are not messed up
    }

 

That's my current code. (As you can see on the comments, I've never really worked with OpenGL, just a bit with OpenGL 3.3 shader's using GLSL!).

Maybe it's also possible to render it with OpenGL 3.3, but I've got no idea if so and how. xD (but I would prefer it)

I'm also wonderin how to draw a point light source in the sphere.

I hope someone can help me.

 

Thx in advance.

Bektor

 

 

Developer of Primeval Forest.

Posted

I'm assuming you can't use an obj model for this? It would be much easier, providing it's a static model.

 

Also TESRs are kinda weird - if you look up at one it will disappear... although I'm sure there's a GLStateManager option to disable this.

Posted

I'm assuming you can't use an obj model for this? It would be much easier, providing it's a static model.

 

Also TESRs are kinda weird - if you look up at one it will disappear... although I'm sure there's a GLStateManager option to disable this.

Well, I want to first test if it's working without a 3d model, because why should I use a 3d model when it can be done without one.

 

Maybe there is a option in the GLStateManager but because I'm not familiar with it I don't know. I just know that my light source

already crashed it with an ArrayOutOfBoundsException. xD

 

The code below is not working. (not sure why)

    private void renderLight(double posX, double posY, double posZ) {
        GlStateManager.enableLighting();
        GL11.glEnable(GL11.GL_LIGHT0); // don't use there GlStateManager .... crashed my game 
        
        float ambientLight[] = { .2f, .2f, .2f, 1.f };
        float diffuseLight[] = { .8f, .8f, .8f, 1.f };
        float specularLight[] = { .5f, .5f, .5f, 1.f };
        float position[] = { (float) posX, (float) posY, (float) posZ, 2.f }; // 4 floats for a position..... o..k...
        
        ByteBuffer temp = ByteBuffer.allocateDirect(16);
        temp.order(ByteOrder.nativeOrder());
        GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, (FloatBuffer)temp.asFloatBuffer().put(ambientLight).flip());
        GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, (FloatBuffer)temp.asFloatBuffer().put(diffuseLight).flip());
        GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, (FloatBuffer)temp.asFloatBuffer().put(specularLight).flip());
        GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, (FloatBuffer)temp.asFloatBuffer().put(position).flip());
        
        GL11.glDisable(GL11.GL_LIGHT0);
        GlStateManager.disableLighting();
    }

 

So any idea how to get the tile entity sphere rendering with this shiny light method above working without using models?

There must be a way, I know it.

 

 

Jabelar goes into some detail on how to render a sphere in one of his tutorials - might be worth checking out.

No change, expect for it that it now renders also when I've got the block not in the hand. But when I move around it disappears again.

 

    private static int sphereIDOutside;
    private static int sphereIDInside;
    
    @Override
    public void renderTileEntityAt(TileEntityPortal tileEntity, double posX, double posY, double posZ, float partialTicks, int destroyStage) {
        GlStateManager.pushMatrix(); // store the transformation 
        GlStateManager.translate(posX, posY, posZ); // set viewport to tile entity position to render it
        
        /* ============ Rendering Code goes here ============ */
        
        GlStateManager.translate(posX + 1f, posY - .6f, posZ + 1f);
        GlStateManager.color(1.f, 1.f, 1.f, .5f);
        GlStateManager.enableBlend(); // enable rendering for transparency
        GlStateManager.depthMask(false);
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        
        GL11.glCallList(TileEntityPortalRenderer.sphereIDOutside);
        GL11.glCallList(TileEntityPortalRenderer.sphereIDInside);
        
        //renderLight(posX, posY, posZ);
        GlStateManager.resetColor();
        GlStateManager.disableBlend();
        
        /* ============ Rendering Code stops here =========== */
        
        GlStateManager.popMatrix(); // restore the transformation, so other renderer's are not messed up
    }
    
    public static void createSphere() {
        Sphere sphere = new Sphere();
        sphere.setDrawStyle(GLU.GLU_FILL); // fill as a solid
        sphere.setNormals(GLU.GLU_SMOOTH); // smooth everything
        
        // First make the call list for the outside of the sphere
        sphere.setOrientation(GLU.GLU_OUTSIDE);
        TileEntityPortalRenderer.sphereIDOutside = GL11.glGenLists(1);
        // Create a new list to hold our sphere data
        GL11.glNewList(TileEntityPortalRenderer.sphereIDOutside, GL11.GL_COMPILE);
        // binds the texture
        ResourceLocation resource = new ResourceLocation(Constants.MOD_ID + ":" + "textures/blocks/sapling_golden.png");
        Minecraft.getMinecraft().getTextureManager().bindTexture(resource);
       
        sphere.draw(1.2f, 32, 32);
        GL11.glEndList();
        
        // Make the call list for the inside of the sphere
        sphere.setOrientation(GLU.GLU_INSIDE);
        TileEntityPortalRenderer.sphereIDInside = GL11.glGenLists(1);
        // Create a new list to hold our sphere data
        GL11.glNewList(TileEntityPortalRenderer.sphereIDInside, GLU.GLU_INSIDE);
        Minecraft.getMinecraft().getTextureManager().bindTexture(resource);
        
        sphere.draw(1.2f, 32, 32);
        GL11.glEndList();
    }

The createSphere() method is called in the client proxy in a method which is called in the init method of the main class.

The texture which was set there is still not used for some reason and the complete thing itself renders like before.

You can see that it's based on pixels and it's flickering. It looks a bit like this:

Only difference, all pixels are green and it's a sphere and the flickering. (sometimes I also noticed the pixels are chaning colours, not sure if it happens with the new code from above).

 

So this didn't solve my problems. It looks like before. (the light source code from above isn't implemented because it's also not working)

 

EDIT: Oh and I'm getting now this thing. Could be that I got it before, too, but before I never saw it or I overlooked it.:

[19:01:13] [Client thread/ERROR] [FML]: Suppressed additional 40 model loading errors for domain primevalforest
[19:01:13] [Client thread/ERROR]: ########## GL ERROR ##########
[19:01:13] [Client thread/ERROR]: @ Post startup

[19:01:13] [Client thread/ERROR]: 1280: Invalid enum

Developer of Primeval Forest.

Posted

Well, I want to first test if it's working without a 3d model, because why should I use a 3d model when it can be done without one.

 

I may be wrong, but I believe 3D models are better for framerate. I don't know for certain, but TESRs seem to be discouraged, given that they update on every frame. Also, models are easier.

But if you need anything custom then TESR is kinda necessary.

 

I am probably wrong. I usually am.

Posted

Well, I want to first test if it's working without a 3d model, because why should I use a 3d model when it can be done without one.

 

I may be wrong, but I believe 3D models are better for framerate. I don't know for certain, but TESRs seem to be discouraged, given that they update on every frame. Also, models are easier.

But if you need anything custom then TESR is kinda necessary.

 

I am probably wrong. I usually am.

I don't think that 3D models are better for framerate. I mean while rendering a 3d object you just render points and lines which connect the lines together and that's what you do when you don't have a model and want to render a sphere. At least from that what I know it's working so.

 

Oh and here are some pics how my sphere looks now:

http://i.imgur.com/JXtNTnJ.png

 

First sphere is totally incorrect drawn, the sphere above doesn't look nice but at least it's a sphere. If I'm farer away both sphere's disappear and when I'm looking from a other

side it looks like there is no sphere. So the sphere is just from ONE side visible.

When I start moving, doesn't matter how much I move all pixels of the sphere begin to move, too. When I stop moving the sphere pixels are still moving around

which really looks horrible. After a few seconds where I don't move the sphere pixels finally stop moving, too and it looks like in the pic above.

 

 

And here is the code:

@SideOnly(Side.CLIENT)
public class TileEntityPortalRenderer extends TileEntitySpecialRenderer<TileEntityPortal> {
    
    public static int sphereIDOutside;
    public static int sphereIDInside;
    
    @Override
    public void renderTileEntityAt(TileEntityPortal tileEntity, double posX, double posY, double posZ, float partialTicks, int destroyStage) {
        GlStateManager.pushMatrix(); // store the transformation 
        GlStateManager.translate(posX, posY, posZ); // set viewport to tile entity position to render it
        
        /* ============ Rendering Code goes here ============ */
        
        GlStateManager.translate(posX + 1f, posY - .6f, posZ + 1f);
        GlStateManager.enableBlend(); // enable rendering for transparency
        GlStateManager.depthMask(false);
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GlStateManager.color(1.f, 1.f, 1.f, .5f);
        GlStateManager.callList(TileEntityPortalRenderer.sphereIDOutside);
        GlStateManager.callList(TileEntityPortalRenderer.sphereIDInside);
        
        //renderLight(posX, posY, posZ);
        GlStateManager.resetColor();
        GlStateManager.disableBlend();
        
        /* ============ Rendering Code stops here =========== */
        
        GlStateManager.popMatrix(); // restore the transformation, so other renderer's are not messed up
    }
    
    public static void createSphere() {
        Sphere sphere = new Sphere();
        sphere.setDrawStyle(GLU.GLU_FILL); // fill as a solid
        sphere.setNormals(GLU.GLU_SMOOTH); // smooth everything
        
        // First make the call list for the outside of the sphere
        sphere.setOrientation(GLU.GLU_OUTSIDE);
        TileEntityPortalRenderer.sphereIDOutside = GL11.glGenLists(1);
        // Create a new list to hold our sphere data
        GL11.glNewList(TileEntityPortalRenderer.sphereIDOutside, GL11.GL_COMPILE);
        // binds the texture
        ResourceLocation resource = new ResourceLocation(Constants.MOD_ID + ":" + "textures/blocks/sapling_golden.png");
        Minecraft.getMinecraft().getTextureManager().bindTexture(resource);
       
        sphere.draw(1.2f, 32, 32);
        GL11.glEndList();
        
        // Make the call list for the inside of the sphere
        sphere.setOrientation(GLU.GLU_INSIDE);
        TileEntityPortalRenderer.sphereIDInside = GL11.glGenLists(1);
        // Create a new list to hold our sphere data
        GL11.glNewList(TileEntityPortalRenderer.sphereIDInside, GLU.GLU_INSIDE);
        Minecraft.getMinecraft().getTextureManager().bindTexture(resource);
        
        sphere.draw(1.2f, 32, 32);
        GL11.glEndList();
    }
}

 

 @Override
    public void init() {
        super.init();
        
        TileEntityPortalRenderer.createSphere();
    }

 

    @Mod.EventHandler
    public void init(FMLInitializationEvent event) {
        PrimevalForest.proxy.init();
    }

 

Any idea how to fix it?

Developer of Primeval Forest.

Posted

If you look in the F3 menu and move, does the pixel changing stop if your movement research 0 ? (the X/Y/Z cords stops changing).

The Sphere disappears if you look from another side, is the render code still running ? And disappears everything at once or are there faces left ?

catch(Exception e)

{

 

}

Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).

Posted

If you look in the F3 menu and move, does the pixel changing stop if your movement research 0 ? (the X/Y/Z cords stops changing).

The Sphere disappears if you look from another side, is the render code still running ? And disappears everything at once or are there faces left ?

I think I should read it up from the xyz coordinates if I'm moving or not. So if I move and then stop moving, the xyz coordinates don't change anymore, the pixels are still changing for a few seconds.

Everything disappears at once.

 

How can I check if the rendering code is still running?

Developer of Primeval Forest.

Posted

Put a break point in your render code and run in debug mode. While in debug mode, you can also edit values in your code and the effects thereof will usually be immediately visible in-game, so you can tweak your render code on the fly until you get it working how you want.

Well, the idea with the breakpoints was a very bad idea. The first project I crashed with break points. ^^

But actually, it's still calling the rendering method, I can't see if it's actually rendered then because I have to press F8 to resume the process and go to the next break point (same position, so next tick) and

then Minecraft automatically opens the ESC menu.

But the render code will be called each tick.

Developer of Primeval Forest.

Posted

Are you sure it wasn't just the break point pausing execution? That's what they do - they pause the program execution without ending the process so that you can examine the state of everything currently on the stack and step through the method calls as they happen.

 

To resume, just press the play/resume button, but if you have a break point in your render code, it will immediately drop you out again the next render tick, so you can toggle the break point off after the first time and then resume.

Posted

Now it worked with the break point. ^^ So, rendering code is executed.

Seems to be it was this stupid windows which thought yeah, program isn't reacting, so it's dead.....

 

But I don't know how to fix the problem now, I'm not that OpenGL pro, I know more OpenGL 3.3 with GLSL fragment shader files etc. then OpenGL 2.1 (and I don't even know much about OpenGL 3.3 ^^)

Developer of Primeval Forest.

Posted

Ok, I've finally found a solution for it. :)

 

        sphere.setTextureFlag(true);

This line of code fixed nearly all bugs with this sphere.

 

Just asking, got anyone an idea why the sphere is disappearing/not drawn when I'm over the sphere?

Developer of Primeval Forest.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I need to know what mod is doing this crash, i mean the mod xenon is doing the crash but i want to know who mod is incompatible with xenon, but please i need to know a solution if i need to replace xenon, i cant use optifine anymore and all the other mods i tried(sodium, lithium, vulkan, etc) doesn't work, it crash the game.
    • I have been trying to solve a consistent crashing issue on my brother's computer where it will crash during the "Scanning Mod Candidates" phase of the loading process that starts when you click the play button on the Minecraft launcher. The issue seems to stem from a missing library that it mentions in the log file I provide below. I might I'm missing the bigger issue here for a smaller one but hopefully someone can find what I'm missing. Here's all of the stuff that I've been able to figure out so far: 1. It has nothing to do with mods, the crash happened with a real modpack, and even when I made a custom modpack and launched it without putting ANY mods into it (That is where the log file comes from by the way). 2. I have tried to find this class like a file in the Minecraft folders, but I've had no luck finding it (I don't think it works like that, but since I really don't understand how it works, I just figured I'd try). 3. I haven't seen anyone else have this issue before. 4. I know that my modpack (with mods) does work since I've run it on my computer, and it works fantastic. For some reason my brother's computer can't seem to run anything through curseforge. 5. This is for Minecraft version 1.20.1, Minecraft launcher version 3.4.50-2.1.3, forge 47.3.0, and curseforge app version 1.256.0.21056 6. My brother is using a Dell laptop from 6 years ago running Windows 10 (If you think more info on this would help, please ask as I do have it. I'm just choosing not to put it here for now). 7. I have reinstalled the curseforge app and installed Minecraft version 1.20.1. I have not reinstalled Minecraft or forge 47.3.0 but I didn't know if that would help. 8. I had an error code of 1 Please let me know if there is anything else that I am missing that you would like me to add to this post/add in a comment! Lastly, many thanks in advance to whoever can help! ------------- LOG FILE (latest.log) ------------- (from /Users/<NAME OF USER>/cursforge/minecraft/Instances/<THE NAME OF MY EMPTY MODPACK>/logs/latest.log) (This was made after running an empty modpack with same versions for all apps) ("[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/hxXvGGEK ------------- DEBUG.LOG (I realized that I should have put this here first after I had done all of the work on putting latest.log in) -------------------- (again, "[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/Fmh8GHYs
    • Pastebin... https://pastebin.com/Y3iZ85L5   Brand new profile, does not point to a mod as far as I can tell, my fatal message just has something about mixins. Don't know much about reading logs like this, but am genuinely stuck, please help. Java updated, pc restarted.
    • I was playing minecraft, forge 47.3.0 and 1.20.1, but when i tried to play minecraft now only crashes, i need help please. here is the crash report: https://securelogger.net/files/e6640a4f-9ed0-4acc-8d06-2e500c77aaaf.txt
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.