Jump to content
  • Advertisement
Sign in to follow this  
ofarooq

OpenGL Drawing a sphere using SlimDx

This topic is 2559 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All, I am new to graphics and slimdx in general. I want to draw a sphere of a given radius. void DrawSphere(float radius, Device device) { ... } I was using the opengl examples(below) but am not sure how to convert it to SlimDX. Thanks void drawSphere(double r, int lats, int longs) { 7 int i, j; 8 for(i = 0; i <= lats; i++) { 9 double lat0 = M_PI * (-0.5 + (double) (i - 1) / lats); 10 double z0 = sin(lat0); 11 double zr0 = cos(lat0); 12 double lat1 = M_PI * (-0.5 + (double) i / lats); 13 double z1 = sin(lat1); 14 double zr1 = cos(lat1); 15 glBegin(GL_QUAD_STRIP); 16 for(j = 0; j <= longs; j++) { 17 double lng = 2 * M_PI * (double) (j - 1) / longs; 18 double x = cos(lng); 19 double y = sin(lng); 20 glNormal3f(x * zr0, y * zr0, z0); 21 glVertex3f(x * zr0, y * zr0, z0); 22 glNormal3f(x * zr1, y * zr1, z1); 23 glVertex3f(x * zr1, y * zr1, z1); 24 } 25 glEnd(); 26 } 27 }

Share this post


Link to post
Share on other sites
Advertisement
Thanks for the quick reply...

so I should do something like this

void Render()
{
...
RenderSphere(device, radius);
}

void RenderSphere(Device device, int r)
{
Mesh.CreateSphere(device, r, 100,100);
}

Is that all. Coz I am not seeing the sphere....

Share this post


Link to post
Share on other sites
Hi
An update

I am doing this

private void RenderLightSphere(Device device)
{
Mesh msh = Mesh.CreateSphere(device, 1, 5, 5);
device.SetStreamSource(0, msh.VertexBuffer, 0, 16);
device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, msh.VertexCount);
}

I can see a bunch of triangles on the screen but no sphere. Obviously I am not using the correct primitive type.
Please advise.

Thanks

Share this post


Link to post
Share on other sites
Firstly, don't create the Mesh each frame, that is going to have MAJOR performance implications.

Secondly, you're not disposing of your Mesh object at all, are you using the debug runtimes? They'll warn you of this.

Finally, Mesh objects use PrimitiveType.TriangleList and you can draw them by calling DrawSubset() instead of binding the vertex/index buffers to the device manually.

Share this post


Link to post
Share on other sites
What about Direct3D11 ? Is there any better way in that ?



If you're using Direct3D 9, the easiest way is probably just to use Mesh.CreateSphere.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!