MANNYWOOD
asked on
render unit sphere 2D, OpenGL
Hey people, I need help rendering a unit sphere to a 2d img. by using the setpixel f'n. It is a 256 x 256.
This below only helps by covering all pixels and shading it white...
for (int x=0; x < 256; x++) {
for (int y = 0; y < 256; y++) {
int Px = ((x/128) - 1);
int Py = ((y/128) - 1);
int Pz = sqrt(Px*Px);
if (sqrt(Px*Px + Py*Py) < 1)
img.setPixel(x, y, Pixel(1.0, 1.0, 1.0));
}
}
I also have to do lighting to shade this to make it look 3D..
Any help will be greatly appreciated! Thanks!
This below only helps by covering all pixels and shading it white...
for (int x=0; x < 256; x++) {
for (int y = 0; y < 256; y++) {
int Px = ((x/128) - 1);
int Py = ((y/128) - 1);
int Pz = sqrt(Px*Px);
if (sqrt(Px*Px + Py*Py) < 1)
img.setPixel(x, y, Pixel(1.0, 1.0, 1.0));
}
}
I also have to do lighting to shade this to make it look 3D..
Any help will be greatly appreciated! Thanks!
ASKER
I'm not too sure still...
The form/ skeleton is already given with the projection, viewing and drawing of the matrix.
I guess when I mean the below only helps by covering all pixels and shading it white, that is the top left box in openGL which has a 256x256 setting and also allows mouse controls to cover pixels in the area. I guess representing a circle really isn't that easy in openGL.
An explained example will defenitley help!, that is.. if you don't mind.
Thanks again jose_juan!
The form/ skeleton is already given with the projection, viewing and drawing of the matrix.
I guess when I mean the below only helps by covering all pixels and shading it white, that is the top left box in openGL which has a 256x256 setting and also allows mouse controls to cover pixels in the area. I guess representing a circle really isn't that easy in openGL.
An explained example will defenitley help!, that is.. if you don't mind.
Thanks again jose_juan!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks~ Hopefully I could understand this.
to simulate 2D render use a glOrtho proyection matrix, in any case, you must use 3D real objects to compund your scene.
Before scene are rendered then get all viewport pixels with glReadPixels.
I think you don't need a realtime execution, in other case, (this way not is bad but) better (and complex) methods are available.
Do you need a explained example?
Good luck!