# Rendering/Modeling Spheres and Circles

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

##### Share on other sites

Do you mean as in blocks?

##### Share on other sites

Do you mean as in blocks?

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

##### Share on other sites

Do you mean as in blocks?

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));

##### 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;

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 +
GL11.glVertex2d(cx + Math.cos(angle + increment)*radius, cy +
GL11.glEnd();
}

Here is what it gives me:

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

Thank you,

Max

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

##### Share on other sites

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

##### 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…

##### 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();

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

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

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

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

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

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

##### Share on other sites

Awesome!

Another cool thing would be to stop drawing half on the way so you could make like a bowl or something

I think this should go into the tutorial section of the wiki, so more people can play around with it…

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

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

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

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.

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

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

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

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

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

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

• ### Posts

• I have recently started working on a server side mod for minecraft 1.20 (1.20-1.20.4), and I want to update the codebase to 1.20.6 but I don't want to create a whole new project. ProjectRoot ├───gradle ├───... ├───src │ └───class_files_in_package ├───build.gradle └───settings.gradle And I want to configure the build.gradle files to achieve something like this: ProjectRoot ├───gradle ├───... ├───forge1_20 │ ├───src │ └───build.gradle ├───forge1_20_6 │ ├───src │ └───build.gradle ├───build.gradle └───settings.gradle Any help would be appriciated.
• Add crash-reports with sites like https://paste.ee/ and paste the link to it here   There is an issue with immediatelyfast
• You CAN add capes, but it requires that you create a custom model for the capes and use something like geckolib or another library that allows for wearable items with physics. You could try to find a tutorial on youtube for custom armor and follow along with that for inspiration in your code
• Having the same problem. Could you let me know if you ever figure it out?
• So I'm making a mod that modifies another mod (Illage and Spillage) with mixins (yes I tried other ways and for what I'm doing there's no other option) and it works fine when launched in IntelliJ, but when I made a .jar of it and exported it and tried to run it, it crashed. (report: https://pastebin.com/G3XNdRKt) I first thought that maybe you can't modify other mods with mixins, but when I looked it up it said you can. Anyone know what's going on?

• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...