Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Rendering/Modeling Spheres and Circles


Maexx
 Share

Recommended Posts

Hello all,

 

I don't have that much experience with rendering (rendering a few simple custom models is all I have done so far), but I wanted to know weather it is possible to render Spheres, Parts of Spheres, Cylinders and all that cool stuff in minecraft.

 

Now, because you practically can do anything in minecraft/java I am sure it is, but what would be necessary to do it ?

 

Thanks,

Max

Link to comment
Share on other sites

Do you mean as in blocks?

 

Thanks for your reply!

 

If you mean doing it like Mojang does it with the Dragon-Egg, by just adding many small boxes in a roundish shape, no.

 

I mean making a perfect sphere without any edges :)

Well to use lwjgl's built in modeling helpers, look into GLU, more specifically quadrics. It includes sphere building methods.

 

To draw a circle, just do a bit of math:

for (int t = 0; t < 2 Pi; t+= stepsize)

  GL11.glVertex2d(Math.sin(t),Math.cos(t));

Link to comment
Share on other sites

 

Well to use lwjgl's built in modeling helpers, look into GLU, more specifically quadrics. It includes sphere building methods.

 

To draw a circle, just do a bit of math:

for (int t = 0; t < 2 Pi; t+= stepsize)

  GL11.glVertex2d(Math.sin(t),Math.cos(t));

 

Hey, Thank you !

 

I extended your code a bit and got it working for a simple circle:

 

Here is the Code:

 

 

        double increment = 2*Math.PI/50;
        double cx = 0.5;
        double cy = 0.5;
        double radius = 0.5;
        
        GL11.glColor4f(1, 0, 0, 1);
      
  	for(double angle = 0; angle < 2*Math.PI; angle+=increment){
  		GL11.glBegin(GL11.GL_POLYGON);
  		GL11.glVertex2d(cx,cy);
  		GL11.glVertex2d(cx + Math.cos(angle)* radius, cy + 
                         Math.sin(angle)*radius);
  		GL11.glVertex2d(cx + Math.cos(angle + increment)*radius, cy + 
                         Math.sin(angle + increment)*radius);
  		GL11.glEnd();
  	}

 

 

 

Here is what it gives me:

 

 

circle-test.png

 

circle-test1.png

 

 

 

 

It renders only from one side and is just a circle and no sphere, but I think this could get something ;)

 

Thank you,

Max

Link to comment
Share on other sites

The problem with that is he is rendering a 2d circle, which you would need to expand into 3 dimensions.

Think of it in terms of circles stacked on top of eachother, with the top/bottom circles be the smallest and the middle being the thickest.

Note that since it needs a lot of vertexes to look smooth, preformance will drop. A lot.

Link to comment
Share on other sites

The problem with that is he is rendering a 2d circle, which you would need to expand into 3 dimensions.

Think of it in terms of circles stacked on top of eachother, with the top/bottom circles be the smallest and the middle being the thickest.

Note that since it needs a lot of vertexes to look smooth, preformance will drop. A lot.

 

Yes, but I don't think you can stack the circles on top of each other to get a sphere, since they don't have any height. And you're right, if it is possible, it would generate way to much lag :(

 

There are also sphere-building methods, according to the person who brought this up. Those are probably better for performance.

 

I found them under org.lwjgl.util.glu.Sphere , however I didn't manage to get any result in-game with them yet…

Link to comment
Share on other sites

Here, I will help you. I tried it out and I see what your problem was, you weren't seeing it because you hadn't set up yet(Probably it was drawing on a transparent section of the currently bound texture).

 

I noticed when rendering spheres that performance dropped a lot, but I found instancing the spheres instead of redrawing them at every render call helped immensely, this is how:

 

First have your proxies both have a method like this: public int sphereID() {}

 

The common should just return 0, but in your Client have it return a static varible named something like public static int sphereID;

 

Now, at the bottom of your Clients RenderingRegistry, add this(This is the important bit):

//GLU.Sphere
        Sphere sphere = new Sphere();
        //GLU_POINT will render it as dots.
        //GLU_LINE will render as wireframe
        //GLU_SILHOUETTE will render as ?shadowed? wireframe
        //GLU_FILL as a solid.
        sphere.setDrawStyle(GLU.GLU_FILL);
        //GLU_SMOOTH will try to smoothly apply lighting
        //GLU_FLAT will have a solid brightness per face, and will not shade.
        //GLU_NONE will be completely solid, and probably will have no depth to it's appearance.        
        sphere.setNormals(GLU.GLU_SMOOTH);
        //GLU_INSIDE will render as if you are inside the sphere, making it appear inside out.(Similar to how ender portals are rendered)
        sphere.setOrientation(GLU.GLU_OUTSIDE);
        //Simple 1x1 red texture to serve as the spheres skin, the only pixel in this image is red.
        BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE);
        bi.setRGB(0, 0, Color.red.getRGB());
        //Bind our texture to a string.
        ForgeHooksClient.textures.put("1x1RED", Minecraft.getMinecraft().renderEngine.allocateAndSetupTexture(bi));
        //sphereID is returned from our sphereID() method
        sphereID = GL11.glGenLists(1);
        //Create a new list to hold our sphere data.
        GL11.glNewList(sphereID, GL11.GL_COMPILE);
        //Offset the sphere by it's radius so it will be centered
        GL11.glTranslatef((float) 0.50F, (float) 0.50F, (float) 0.50F);
        //Call our string that we mapped to our texture
        ForgeHooksClient.bindTexture("1x1RED", 0);
        //The drawing the sphere is automattically doing is getting added to our list. Careful, the last 2 variables 
       //control the detail, but have a massive impact on performance. 32x32 is a good balance on my machine.
        sphere.draw(0.5F, 32, 32);
        //Drawing done, unbind our texture
        ForgeHooksClient.unbindTexture();
        //Tell LWJGL that we are done creating our list.
        GL11.glEndList();

 

Now, in our rending class, when you need to render the sphere, do this:

GL11.glPushMatrix();
//Default parameters in TileEntitySpecialRenderer's renderTileEntityAt
GL11.glTranslatef((float) var2, (float) var4, (float) var6);
GL11.glCallList(YourModClass.proxy.sphereID());
GL11.glPopMatrix();

Link to comment
Share on other sites

Here, I will help you. I tried it out and I see what your problem was, you weren't seeing it because you hadn't set up yet(Probably it was drawing on a transparent section of the currently bound texture).

 

I noticed when rendering spheres that performance dropped a lot, but I found instancing the spheres instead of redrawing them at every render call helped immensely, this is how:

 

First have your proxies both have a method like this: public int sphereID() {}

 

The common should just return 0, but in your Client have it return a static varible named something like public static int sphereID;

 

Now, at the bottom of your Clients RenderingRegistry, add this(This is the important bit):

//GLU.Sphere
        Sphere sphere = new Sphere();
        //GLU_POINT will render it as dots.
        //GLU_LINE will render as wireframe
        //GLU_SILHOUETTE will render as ?shadowed? wireframe
        //GLU_FILL as a solid.
        sphere.setDrawStyle(GLU.GLU_FILL);
        //GLU_SMOOTH will try to smoothly apply lighting
        //GLU_FLAT will have a solid brightness per face, and will not shade.
        //GLU_NONE will be completely solid, and probably will have no depth to it's appearance.        
        sphere.setNormals(GLU.GLU_SMOOTH);
        //GLU_INSIDE will render as if you are inside the sphere, making it appear inside out.(Similar to how ender portals are rendered)
        sphere.setOrientation(GLU.GLU_OUTSIDE);
        //Simple 1x1 red texture to serve as the spheres skin, the only pixel in this image is red.
        BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE);
        bi.setRGB(0, 0, Color.red.getRGB());
        //Bind our texture to a string.
        ForgeHooksClient.textures.put("1x1RED", Minecraft.getMinecraft().renderEngine.allocateAndSetupTexture(bi));
        //sphereID is returned from our sphereID() method
        sphereID = GL11.glGenLists(1);
        //Create a new list to hold our sphere data.
        GL11.glNewList(sphereID, GL11.GL_COMPILE);
        //Offset the sphere by it's radius so it will be centered
        GL11.glTranslatef((float) 0.50F, (float) 0.50F, (float) 0.50F);
        //Call our string that we mapped to our texture
        ForgeHooksClient.bindTexture("1x1RED", 0);
        //The drawing the sphere is automattically doing is getting added to our list. Careful, the last 2 variables 
       //control the detail, but have a massive impact on performance. 32x32 is a good balance on my machine.
        sphere.draw(0.5F, 32, 32);
        //Drawing done, unbind our texture
        ForgeHooksClient.unbindTexture();
        //Tell LWJGL that we are done creating our list.
        GL11.glEndList();

 

Now, in our rending class, when you need to render the sphere, do this:

GL11.glPushMatrix();
//Default parameters in TileEntitySpecialRenderer's renderTileEntityAt
GL11.glTranslatef((float) var2, (float) var4, (float) var6);
GL11.glCallList(YourModClass.proxy.sphereID());
GL11.glPopMatrix();

 

I set the texture to a 1x1 White Texture so I can set the color before calling it, and it works brilliantly.

 

I did notice however, how damn out of place spheres are in minecraft.

Link to comment
Share on other sites

Here, I will help you. I tried it out and I see what your problem was, you weren't seeing it because you hadn't set up yet(Probably it was drawing on a transparent section of the currently bound texture).

 

I noticed when rendering spheres that performance dropped a lot, but I found instancing the spheres instead of redrawing them at every render call helped immensely, this is how:

 

First have your proxies both have a method like this: public int sphereID() {}

 

The common should just return 0, but in your Client have it return a static varible named something like public static int sphereID;

 

Now, at the bottom of your Clients RenderingRegistry, add this(This is the important bit):

//GLU.Sphere
        Sphere sphere = new Sphere();
        //GLU_POINT will render it as dots.
        //GLU_LINE will render as wireframe
        //GLU_SILHOUETTE will render as ?shadowed? wireframe
        //GLU_FILL as a solid.
        sphere.setDrawStyle(GLU.GLU_FILL);
        //GLU_SMOOTH will try to smoothly apply lighting
        //GLU_FLAT will have a solid brightness per face, and will not shade.
        //GLU_NONE will be completely solid, and probably will have no depth to it's appearance.        
        sphere.setNormals(GLU.GLU_SMOOTH);
        //GLU_INSIDE will render as if you are inside the sphere, making it appear inside out.(Similar to how ender portals are rendered)
        sphere.setOrientation(GLU.GLU_OUTSIDE);
        //Simple 1x1 red texture to serve as the spheres skin, the only pixel in this image is red.
        BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE);
        bi.setRGB(0, 0, Color.red.getRGB());
        //Bind our texture to a string.
        ForgeHooksClient.textures.put("1x1RED", Minecraft.getMinecraft().renderEngine.allocateAndSetupTexture(bi));
        //sphereID is returned from our sphereID() method
        sphereID = GL11.glGenLists(1);
        //Create a new list to hold our sphere data.
        GL11.glNewList(sphereID, GL11.GL_COMPILE);
        //Offset the sphere by it's radius so it will be centered
        GL11.glTranslatef((float) 0.50F, (float) 0.50F, (float) 0.50F);
        //Call our string that we mapped to our texture
        ForgeHooksClient.bindTexture("1x1RED", 0);
        //The drawing the sphere is automattically doing is getting added to our list. Careful, the last 2 variables 
       //control the detail, but have a massive impact on performance. 32x32 is a good balance on my machine.
        sphere.draw(0.5F, 32, 32);
        //Drawing done, unbind our texture
        ForgeHooksClient.unbindTexture();
        //Tell LWJGL that we are done creating our list.
        GL11.glEndList();

 

Now, in our rending class, when you need to render the sphere, do this:

GL11.glPushMatrix();
//Default parameters in TileEntitySpecialRenderer's renderTileEntityAt
GL11.glTranslatef((float) var2, (float) var4, (float) var6);
GL11.glCallList(YourModClass.proxy.sphereID());
GL11.glPopMatrix();

 

Thank you a lot, I am going to try this right now :)

 

 

I did notice however, how damn out of place spheres are in minecraft.

 

You are probably right, but it is cool anyways...and if you use them in the right spots and not to often I think you could create some cool looking blocks :)

 

Link to comment
Share on other sites

Here, I will help you. I tried it out and I see what your problem was, you weren't seeing it because you hadn't set up yet(Probably it was drawing on a transparent section of the currently bound texture).

 

I noticed when rendering spheres that performance dropped a lot, but I found instancing the spheres instead of redrawing them at every render call helped immensely, this is how:

 

First have your proxies both have a method like this: public int sphereID() {}

 

The common should just return 0, but in your Client have it return a static varible named something like public static int sphereID;

 

Now, at the bottom of your Clients RenderingRegistry, add this(This is the important bit):

//GLU.Sphere
        Sphere sphere = new Sphere();
        //GLU_POINT will render it as dots.
        //GLU_LINE will render as wireframe
        //GLU_SILHOUETTE will render as ?shadowed? wireframe
        //GLU_FILL as a solid.
        sphere.setDrawStyle(GLU.GLU_FILL);
        //GLU_SMOOTH will try to smoothly apply lighting
        //GLU_FLAT will have a solid brightness per face, and will not shade.
        //GLU_NONE will be completely solid, and probably will have no depth to it's appearance.        
        sphere.setNormals(GLU.GLU_SMOOTH);
        //GLU_INSIDE will render as if you are inside the sphere, making it appear inside out.(Similar to how ender portals are rendered)
        sphere.setOrientation(GLU.GLU_OUTSIDE);
        //Simple 1x1 red texture to serve as the spheres skin, the only pixel in this image is red.
        BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE);
        bi.setRGB(0, 0, Color.red.getRGB());
        //Bind our texture to a string.
        ForgeHooksClient.textures.put("1x1RED", Minecraft.getMinecraft().renderEngine.allocateAndSetupTexture(bi));
        //sphereID is returned from our sphereID() method
        sphereID = GL11.glGenLists(1);
        //Create a new list to hold our sphere data.
        GL11.glNewList(sphereID, GL11.GL_COMPILE);
        //Offset the sphere by it's radius so it will be centered
        GL11.glTranslatef((float) 0.50F, (float) 0.50F, (float) 0.50F);
        //Call our string that we mapped to our texture
        ForgeHooksClient.bindTexture("1x1RED", 0);
        //The drawing the sphere is automattically doing is getting added to our list. Careful, the last 2 variables 
       //control the detail, but have a massive impact on performance. 32x32 is a good balance on my machine.
        sphere.draw(0.5F, 32, 32);
        //Drawing done, unbind our texture
        ForgeHooksClient.unbindTexture();
        //Tell LWJGL that we are done creating our list.
        GL11.glEndList();

 

Now, in our rending class, when you need to render the sphere, do this:

GL11.glPushMatrix();
//Default parameters in TileEntitySpecialRenderer's renderTileEntityAt
GL11.glTranslatef((float) var2, (float) var4, (float) var6);
GL11.glCallList(YourModClass.proxy.sphereID());
GL11.glPopMatrix();

 

I set the texture to a 1x1 White Texture so I can set the color before calling it, and it works brilliantly.

 

I did notice however, how damn out of place spheres are in minecraft.

I'd like to see it sounds cool

Link to comment
Share on other sites

Here, I will help you. I tried it out and I see what your problem was, you weren't seeing it because you hadn't set up yet(Probably it was drawing on a transparent section of the currently bound texture).

 

I noticed when rendering spheres that performance dropped a lot, but I found instancing the spheres instead of redrawing them at every render call helped immensely, this is how:

 

First have your proxies both have a method like this: public int sphereID() {}

 

The common should just return 0, but in your Client have it return a static varible named something like public static int sphereID;

 

Now, at the bottom of your Clients RenderingRegistry, add this(This is the important bit):

//GLU.Sphere
        Sphere sphere = new Sphere();
        //GLU_POINT will render it as dots.
        //GLU_LINE will render as wireframe
        //GLU_SILHOUETTE will render as ?shadowed? wireframe
        //GLU_FILL as a solid.
        sphere.setDrawStyle(GLU.GLU_FILL);
        //GLU_SMOOTH will try to smoothly apply lighting
        //GLU_FLAT will have a solid brightness per face, and will not shade.
        //GLU_NONE will be completely solid, and probably will have no depth to it's appearance.        
        sphere.setNormals(GLU.GLU_SMOOTH);
        //GLU_INSIDE will render as if you are inside the sphere, making it appear inside out.(Similar to how ender portals are rendered)
        sphere.setOrientation(GLU.GLU_OUTSIDE);
        //Simple 1x1 red texture to serve as the spheres skin, the only pixel in this image is red.
        BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE);
        bi.setRGB(0, 0, Color.red.getRGB());
        //Bind our texture to a string.
        ForgeHooksClient.textures.put("1x1RED", Minecraft.getMinecraft().renderEngine.allocateAndSetupTexture(bi));
        //sphereID is returned from our sphereID() method
        sphereID = GL11.glGenLists(1);
        //Create a new list to hold our sphere data.
        GL11.glNewList(sphereID, GL11.GL_COMPILE);
        //Offset the sphere by it's radius so it will be centered
        GL11.glTranslatef((float) 0.50F, (float) 0.50F, (float) 0.50F);
        //Call our string that we mapped to our texture
        ForgeHooksClient.bindTexture("1x1RED", 0);
        //The drawing the sphere is automattically doing is getting added to our list. Careful, the last 2 variables 
       //control the detail, but have a massive impact on performance. 32x32 is a good balance on my machine.
        sphere.draw(0.5F, 32, 32);
        //Drawing done, unbind our texture
        ForgeHooksClient.unbindTexture();
        //Tell LWJGL that we are done creating our list.
        GL11.glEndList();

 

Now, in our rending class, when you need to render the sphere, do this:

GL11.glPushMatrix();
//Default parameters in TileEntitySpecialRenderer's renderTileEntityAt
GL11.glTranslatef((float) var2, (float) var4, (float) var6);
GL11.glCallList(YourModClass.proxy.sphereID());
GL11.glPopMatrix();

 

I set the texture to a 1x1 White Texture so I can set the color before calling it, and it works brilliantly.

 

I did notice however, how damn out of place spheres are in minecraft.

I'd like to see it sounds cool

Very well. It is not a mod, I as just playing with the idea, but this is how it looks. I made it so it generates a random color when placed so I can get a large color variation without much effort.

 

Here is the screenshot.

Link to comment
Share on other sites

Very well. It is not a mod, I as just playing with the idea, but this is how it looks. I made it so it generates a random color when placed so I can get a large color variation without much effort.

 

Here is the screenshot.

Looking good. Are you going to do anything with it?

 

I didn't realize giving people this information would get as much attention, I guess it is something people have actually thought about.

 

One of you should code some rudimentary physics, and make a soccer ball / bouncy ball :P

Link to comment
Share on other sites

Here, I will help you. I tried it out and I see what your problem was, you weren't seeing it because you hadn't set up yet(Probably it was drawing on a transparent section of the currently bound texture).

 

I noticed when rendering spheres that performance dropped a lot, but I found instancing the spheres instead of redrawing them at every render call helped immensely, this is how:

 

First have your proxies both have a method like this: public int sphereID() {}

 

The common should just return 0, but in your Client have it return a static varible named something like public static int sphereID;

 

Now, at the bottom of your Clients RenderingRegistry, add this(This is the important bit):

//GLU.Sphere
        Sphere sphere = new Sphere();
        //GLU_POINT will render it as dots.
        //GLU_LINE will render as wireframe
        //GLU_SILHOUETTE will render as ?shadowed? wireframe
        //GLU_FILL as a solid.
        sphere.setDrawStyle(GLU.GLU_FILL);
        //GLU_SMOOTH will try to smoothly apply lighting
        //GLU_FLAT will have a solid brightness per face, and will not shade.
        //GLU_NONE will be completely solid, and probably will have no depth to it's appearance.        
        sphere.setNormals(GLU.GLU_SMOOTH);
        //GLU_INSIDE will render as if you are inside the sphere, making it appear inside out.(Similar to how ender portals are rendered)
        sphere.setOrientation(GLU.GLU_OUTSIDE);
        //Simple 1x1 red texture to serve as the spheres skin, the only pixel in this image is red.
        BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE);
        bi.setRGB(0, 0, Color.red.getRGB());
        //Bind our texture to a string.
        ForgeHooksClient.textures.put("1x1RED", Minecraft.getMinecraft().renderEngine.allocateAndSetupTexture(bi));
        //sphereID is returned from our sphereID() method
        sphereID = GL11.glGenLists(1);
        //Create a new list to hold our sphere data.
        GL11.glNewList(sphereID, GL11.GL_COMPILE);
        //Offset the sphere by it's radius so it will be centered
        GL11.glTranslatef((float) 0.50F, (float) 0.50F, (float) 0.50F);
        //Call our string that we mapped to our texture
        ForgeHooksClient.bindTexture("1x1RED", 0);
        //The drawing the sphere is automattically doing is getting added to our list. Careful, the last 2 variables 
       //control the detail, but have a massive impact on performance. 32x32 is a good balance on my machine.
        sphere.draw(0.5F, 32, 32);
        //Drawing done, unbind our texture
        ForgeHooksClient.unbindTexture();
        //Tell LWJGL that we are done creating our list.
        GL11.glEndList();

 

Now, in our rending class, when you need to render the sphere, do this:

GL11.glPushMatrix();
//Default parameters in TileEntitySpecialRenderer's renderTileEntityAt
GL11.glTranslatef((float) var2, (float) var4, (float) var6);
GL11.glCallList(YourModClass.proxy.sphereID());
GL11.glPopMatrix();

 

I set the texture to a 1x1 White Texture so I can set the color before calling it, and it works brilliantly.

 

I did notice however, how damn out of place spheres are in minecraft.

I'd like to see it sounds cool

Very well. It is not a mod, I as just playing with the idea, but this is how it looks. I made it so it generates a random color when placed so I can get a large color variation without much effort.

 

Here is the screenshot.

that is to cool do you mind if i do things with this to?

 

Link to comment
Share on other sites

Here, I will help you. I tried it out and I see what your problem was, you weren't seeing it because you hadn't set up yet(Probably it was drawing on a transparent section of the currently bound texture).

 

I noticed when rendering spheres that performance dropped a lot, but I found instancing the spheres instead of redrawing them at every render call helped immensely, this is how:

 

First have your proxies both have a method like this: public int sphereID() {}

 

The common should just return 0, but in your Client have it return a static varible named something like public static int sphereID;

 

Now, at the bottom of your Clients RenderingRegistry, add this(This is the important bit):

//GLU.Sphere
        Sphere sphere = new Sphere();
        //GLU_POINT will render it as dots.
        //GLU_LINE will render as wireframe
        //GLU_SILHOUETTE will render as ?shadowed? wireframe
        //GLU_FILL as a solid.
        sphere.setDrawStyle(GLU.GLU_FILL);
        //GLU_SMOOTH will try to smoothly apply lighting
        //GLU_FLAT will have a solid brightness per face, and will not shade.
        //GLU_NONE will be completely solid, and probably will have no depth to it's appearance.        
        sphere.setNormals(GLU.GLU_SMOOTH);
        //GLU_INSIDE will render as if you are inside the sphere, making it appear inside out.(Similar to how ender portals are rendered)
        sphere.setOrientation(GLU.GLU_OUTSIDE);
        //Simple 1x1 red texture to serve as the spheres skin, the only pixel in this image is red.
        BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE);
        bi.setRGB(0, 0, Color.red.getRGB());
        //Bind our texture to a string.
        ForgeHooksClient.textures.put("1x1RED", Minecraft.getMinecraft().renderEngine.allocateAndSetupTexture(bi));
        //sphereID is returned from our sphereID() method
        sphereID = GL11.glGenLists(1);
        //Create a new list to hold our sphere data.
        GL11.glNewList(sphereID, GL11.GL_COMPILE);
        //Offset the sphere by it's radius so it will be centered
        GL11.glTranslatef((float) 0.50F, (float) 0.50F, (float) 0.50F);
        //Call our string that we mapped to our texture
        ForgeHooksClient.bindTexture("1x1RED", 0);
        //The drawing the sphere is automattically doing is getting added to our list. Careful, the last 2 variables 
       //control the detail, but have a massive impact on performance. 32x32 is a good balance on my machine.
        sphere.draw(0.5F, 32, 32);
        //Drawing done, unbind our texture
        ForgeHooksClient.unbindTexture();
        //Tell LWJGL that we are done creating our list.
        GL11.glEndList();

 

Now, in our rending class, when you need to render the sphere, do this:

GL11.glPushMatrix();
//Default parameters in TileEntitySpecialRenderer's renderTileEntityAt
GL11.glTranslatef((float) var2, (float) var4, (float) var6);
GL11.glCallList(YourModClass.proxy.sphereID());
GL11.glPopMatrix();

 

I set the texture to a 1x1 White Texture so I can set the color before calling it, and it works brilliantly.

 

I did notice however, how damn out of place spheres are in minecraft.

I'd like to see it sounds cool

Very well. It is not a mod, I as just playing with the idea, but this is how it looks. I made it so it generates a random color when placed so I can get a large color variation without much effort.

 

Here is the screenshot.

that is to cool do you mind if i do things with this to?

I Posted the code as a tutorial, do what you want.

Link to comment
Share on other sites

Here, I will help you. I tried it out and I see what your problem was, you weren't seeing it because you hadn't set up yet(Probably it was drawing on a transparent section of the currently bound texture).

 

I noticed when rendering spheres that performance dropped a lot, but I found instancing the spheres instead of redrawing them at every render call helped immensely, this is how:

 

First have your proxies both have a method like this: public int sphereID() {}

 

The common should just return 0, but in your Client have it return a static varible named something like public static int sphereID;

 

Now, at the bottom of your Clients RenderingRegistry, add this(This is the important bit):

//GLU.Sphere
        Sphere sphere = new Sphere();
        //GLU_POINT will render it as dots.
        //GLU_LINE will render as wireframe
        //GLU_SILHOUETTE will render as ?shadowed? wireframe
        //GLU_FILL as a solid.
        sphere.setDrawStyle(GLU.GLU_FILL);
        //GLU_SMOOTH will try to smoothly apply lighting
        //GLU_FLAT will have a solid brightness per face, and will not shade.
        //GLU_NONE will be completely solid, and probably will have no depth to it's appearance.        
        sphere.setNormals(GLU.GLU_SMOOTH);
        //GLU_INSIDE will render as if you are inside the sphere, making it appear inside out.(Similar to how ender portals are rendered)
        sphere.setOrientation(GLU.GLU_OUTSIDE);
        //Simple 1x1 red texture to serve as the spheres skin, the only pixel in this image is red.
        BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB_PRE);
        bi.setRGB(0, 0, Color.red.getRGB());
        //Bind our texture to a string.
        ForgeHooksClient.textures.put("1x1RED", Minecraft.getMinecraft().renderEngine.allocateAndSetupTexture(bi));
        //sphereID is returned from our sphereID() method
        sphereID = GL11.glGenLists(1);
        //Create a new list to hold our sphere data.
        GL11.glNewList(sphereID, GL11.GL_COMPILE);
        //Offset the sphere by it's radius so it will be centered
        GL11.glTranslatef((float) 0.50F, (float) 0.50F, (float) 0.50F);
        //Call our string that we mapped to our texture
        ForgeHooksClient.bindTexture("1x1RED", 0);
        //The drawing the sphere is automattically doing is getting added to our list. Careful, the last 2 variables 
       //control the detail, but have a massive impact on performance. 32x32 is a good balance on my machine.
        sphere.draw(0.5F, 32, 32);
        //Drawing done, unbind our texture
        ForgeHooksClient.unbindTexture();
        //Tell LWJGL that we are done creating our list.
        GL11.glEndList();

 

Now, in our rending class, when you need to render the sphere, do this:

GL11.glPushMatrix();
//Default parameters in TileEntitySpecialRenderer's renderTileEntityAt
GL11.glTranslatef((float) var2, (float) var4, (float) var6);
GL11.glCallList(YourModClass.proxy.sphereID());
GL11.glPopMatrix();

 

I set the texture to a 1x1 White Texture so I can set the color before calling it, and it works brilliantly.

 

I did notice however, how damn out of place spheres are in minecraft.

I'd like to see it sounds cool

Very well. It is not a mod, I as just playing with the idea, but this is how it looks. I made it so it generates a random color when placed so I can get a large color variation without much effort.

 

Here is the screenshot.

that is to cool do you mind if i do things with this to?

I Posted the code as a tutorial, do what you want.

is there any way to make them smoother also invert the shape like a cube with a  cut out of the center or even a sphere in side that also it'd be nice if you could do a  on on creating other shapes in minecraft there rely aren't  enough up to date  tutorials on the wiki

Link to comment
Share on other sites

Well, without using shaders(advanced, not all cards support it), you would increase the stack and slice count, but spheres are incredibly intensive.

 

'sphere.draw(0.5F, 32, 32);' the last 2 control the detail, first, how many slices, and the other is stacks. Basically, vertical and horizontal quality.

 

As quality of the sphere increases, performance decreases non-linearly. Basically meaning after a certain point, the quality gain is not worth the cost(which is why modern cards now have tesselation acceleration, so they can get high quality rounded and high detail objects).

 

You could play with the stack and slice count to find what you like best. By increasing the slice to stack ratio, the sphere sports a grid shading as opposed to what you see in the picture TroubleDad posted. Like this:

sphere.draw(0.5F, 48, 24);

 

That would give you similar performance, but the shading might be more attractive to you. Also, using GLU_FLAT instead of GLU_SMOOTH not only can increase performance in spheres, it might give it a better appearance, and hide the sharp edges.

 

You can't simply remove 1 side of a cube and open it up, you have to connect it, so you have to do this:

_            _

||            ||

||            ||

||______||

--------------

 

Also, you cold draw a sphere within a sphere, by making the larger sphere transparent, and the inner sphere have a smaller radius.

 

 

sphere.draw(0.5F, 128,64); with sphere.setNormals(GLU.GLU_FLAT); gives me a near perfect sphere, and even with 20 of them in view, I cannot see any noticeable fps drop on my modern system(but this will vary greatly on older systems).

 

Here is an Image

width=800 height=449https://dl.dropbox.com/u/74770478/2012-12-09_18.04.24.png[/img]

Link to comment
Share on other sites

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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.