Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Is there a way to render textured spheres without using OpenGL?  (Read 8032 times)

0 Members and 1 Guest are viewing this topic.

BruceJohnJennerLawso

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • My Code on Github
Okay, so I am working on a space simulator type project in 2D. The Vessels are rendered as flat sprites, which is simple enough, but for the planets and moons I would like to be able to render them as 3d spheres with a rectangular texture mapped to their surfaces. Obviously, the most direct way of doing this would be to use OpenGL, but I would rather not devote all of that time & add another dependency to my project just to do one very simple thing involving 3d graphics.

So my question was, has anyone ever developed any sort of sf::Drawable child class that can take a rectangular texture as input and draw it onscreen as a textured sphere? Or are there any other options that I am missing here that I could try instead?
Quote
The computer is mightier than the pen, the sword, and usually the programmer.

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Re: Is there a way to render textured spheres without using OpenGL?
« Reply #1 on: March 03, 2015, 10:21:18 pm »
The only way is to use OpenGL. SFML already relies on OpenGL, so it would not be another dependency. Although, if your simulator is 2D, you don't need to render a sphere. You could just render a textured circle.
« Last Edit: March 03, 2015, 10:22:50 pm by OniLinkPlus »
I use the latest build of SFML2

BruceJohnJennerLawso

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • My Code on Github
Re: Is there a way to render textured spheres without using OpenGL?
« Reply #2 on: March 03, 2015, 11:25:36 pm »
Wait, really? So I can just call OpenGL calls from inside of SFML without ever needing to bother with linking to the OpenGL libraries?

I have been doing the solution with rendering a textured circle, but its really not a good fit for the task. Its hard to properly crop and center an image of a planet at ~ 1600 pixels square, so it causes a lot of problems, like the ground not corresponding to where the ground in the image is. Its a really hacky solution to be honest.
Quote
The computer is mightier than the pen, the sword, and usually the programmer.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Is there a way to render textured spheres without using OpenGL?
« Reply #3 on: March 04, 2015, 07:35:27 am »
Quote
So I can just call OpenGL calls from inside of SFML without ever needing to bother with linking to the OpenGL libraries?
SFML provides a unified header (SFML/OpenGL.hpp) but it can't link the OpenGL library for you. But it's not like adding -lopengl to your linker settings is hard to do :P
Laurent Gomila - SFML developer

BruceJohnJennerLawso

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • My Code on Github
Re: Is there a way to render textured spheres without using OpenGL?
« Reply #4 on: March 04, 2015, 10:27:22 pm »
Weirdly enough, it works even without that. My link settings are

g++ hellogl.o -o hellogl -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio

and it works.

So I guess the only way of rendering a textured sphere would be to do it as a set of triangles, like described here:

http://stackoverflow.com/questions/7687148/drawing-sphere-in-opengl-without-using-glusphere

But in order to texture it I will need to somehow break up the image of the planet into triangular segments and map them to each triangle in the sphere. Is there a way to load a sf::Texture and map it to a openGL entity?
Quote
The computer is mightier than the pen, the sword, and usually the programmer.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Is there a way to render textured spheres without using OpenGL?
« Reply #5 on: March 04, 2015, 10:35:22 pm »
Quote
Is there a way to load a sf::Texture and map it to a openGL entity?
It's explained in the doc.
Laurent Gomila - SFML developer

BruceJohnJennerLawso

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • My Code on Github
Re: Is there a way to render textured spheres without using OpenGL?
« Reply #6 on: March 04, 2015, 11:05:36 pm »
In the API docs? Theres nothing about it in here:

http://www.sfml-dev.org/tutorials/2.2/window-opengl.php

Edit: nevermind, found it. How exactly would I break up a rectangular texture into triangles though?
« Last Edit: March 04, 2015, 11:08:59 pm by BruceJohnJennerLawso »
Quote
The computer is mightier than the pen, the sword, and usually the programmer.

Ztormi

  • Jr. Member
  • **
  • Posts: 71
  • Web developer by day. Game developer by night.
    • View Profile
Re: Is there a way to render textured spheres without using OpenGL?
« Reply #7 on: March 05, 2015, 09:24:21 am »
If you don't have to freely move around 3d space another approach would be to render quad with shader creating a fake 3d sphere effect.

http://www.geeks3d.com/20110316/shader-library-simple-2d-effects-sphere-and-ripple-in-glsl/
http://gamedev.stackexchange.com/questions/9346/2d-shader-to-draw-representation-of-rotating-sphere

Here's one using fractals as texture:
http://glslsandbox.com/e#23364.0

BruceJohnJennerLawso

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • My Code on Github
Re: Is there a way to render textured spheres without using OpenGL?
« Reply #8 on: March 06, 2015, 03:33:26 am »
Thanks for posting those links, they look very helpful. In the case of the first shader, what drawable entity would I apply it to in SFML, the planets rectangular texture map?
Quote
The computer is mightier than the pen, the sword, and usually the programmer.

Ztormi

  • Jr. Member
  • **
  • Posts: 71
  • Web developer by day. Game developer by night.
    • View Profile
Re: Is there a way to render textured spheres without using OpenGL?
« Reply #9 on: March 06, 2015, 11:26:26 am »
Sprite would do.

Tested the first shader myself and it seems to work nicely with slight modifications.

BruceJohnJennerLawso

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • My Code on Github
Re: Is there a way to render textured spheres without using OpenGL?
« Reply #10 on: March 07, 2015, 08:57:11 pm »
What did you change with it to get it working? I havent had any luck with it so far.
Quote
The computer is mightier than the pen, the sword, and usually the programmer.