Posted April 9, 20169 yr 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. (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.
April 9, 20169 yr 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.
April 9, 20169 yr Jabelar goes into some detail on how to render a sphere in one of his tutorials - might be worth checking out. http://i.imgur.com/NdrFdld.png[/img]
April 9, 20169 yr Author 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. 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.
April 9, 20169 yr 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.
April 10, 20169 yr Author 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.
April 10, 20169 yr 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).
April 10, 20169 yr Author 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.
April 10, 20169 yr 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. http://i.imgur.com/NdrFdld.png[/img]
April 10, 20169 yr Author 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.
April 10, 20169 yr If it's showing the escape menu because it thinks it's lost focus or whatever, do F3+P and it won't auto-pause.
April 10, 20169 yr 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. http://i.imgur.com/NdrFdld.png[/img]
April 10, 20169 yr Author 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.
April 11, 20169 yr Author Hm, I've copied an pasted now the complete tutorial code in and replaced my complete code with it and I'm still getting the same problems. I'm really out of ideas what's wrong... Developer of Primeval Forest.
April 11, 20169 yr Author 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.