using opengl and java to draw pentagon or triangle moving in a circle

how to draw  pentagon or triangle (wireframe for lines and solid for triangles) rotating in a circle using java.  Apply the Bresenham's line algorithm or a triangle filling scan-conversion algorithm.
david-leeAsked:
Who is Participating?
 
Jose ParrotConnect With a Mentor Graphics ExpertCommented:
We don't use Breseham's or other algorithms to draw lines by ourselves, when we use OpenGL. The same applies to filling polygons. OpenGL has functions to draw any polygon in wire frame or solid.
If your program must draw the lines or fill polygons, in a pixel by pixel basis, you don't need OpenGL. By the way, it will be extremely slower than OpenGL.
If you want to mix OpenGL and Java, take a look at
http://www.javaworld.com/javaworld/jw-05-1999/jw-05-media.html
to understand the problems we have to join them...
I noticed the DHTML zone, so I'm assuming your objective is to develop a web page with 2D animated entities: triangles and pentagons, so, if my assumption is correct, consider the following combinations:
  • java and html, it is OK;
  • java and OpenGL, it is bad;
  • java + OpenGL + HTML; this is a confusion.
If you need interactive, high performance 3D, OpenGL and C++ to run in your computer, that's perfect.
If you need just 2D simple animation, take a look at Flash. Easer, simpler, faster to develop and perfectly adequated to a web page.
Jose
0
 
david-leeAuthor Commented:
may be I selected wrong zone.  my problem is to draw a circle then fill color triangle which can be rotated inside the circle.  the requirement is filling scan conversion algorithm.  the language is java with opengl.  this is computer graphic program, not for web design.  I do not know C++.
0
 
Jose ParrotConnect With a Mentor Graphics ExpertCommented:
At http://www.gamedev.net/reference/articles/article767.asp
there is a complete tutorial, so you can learn how Bresenham's algorithms calculate the pixels for lines and circles. There are Pascal programs there, which can be translated to java.
By the way, if you find C or C++ code it is easy to translate it to java, don't worry about.

If you must develop Breseham lines and circles, what is the purpose of using OpenGL? Do you will use OpenGL just to draw pixels? This is not a right approach to that objective.
To be efficient, the program should set pixels, in general, by using direct access to the graphic board, by using assembler or C. Or, better, by calling OpenGL functions directly to draw graphics primitives.
But, if you MUST use OpenGL you need Java JDK and JOGL. You can download them from http://opengl.j3d.org/installing.html
Let me suggest to read the Java OpenGL FAQ: http://opengl.j3d.org/faq/index.html
The difficult I have to answer directly what you are looking for is that I never read about Java + OpenGL + Breseham. Some considerations:
  • Java + OpenGL
    I have no experience on that, but know that JOGL is the right approach.
    To draw a line, the Java code calls OpenGL functions as in CODE_1 below.
  • Line algorithm in Java + OpenGL
    Makes no sense a slow program (Java, C#) to calculate pixel by pixel in a loop (Breseham or not) and to ask OpenGL just to draw it in a pixel by pixel basis, as in CODE_2 below.
    OpenGL is a powerful 3D environment (can be used also for 2D) and that approach will result in a very slow execution.
  • Breseham
    Useful if developed in assembler or in a high speed language with direct access to video memory. Makes no sense calculate each pixel in 0.001 second and spend 0.05 s to draw it in the screen, if I can draw the entire line in 0.005 s.
    Extremely useful if writen in machine code inside a graphics card firmware.
The same reasons apply to circle also. Anyway, the generic ellipse algorithm can be found at http://www.robots.ox.ac.uk/~awf/graphics/bres-ellipse.html If you need a circle, just make the axies equal.
Finnaly, every time I write or read about Breseham's algorithm, I make a wow to the brilliant Mr. Jack, who created it in 1962 when he was with IBM.
Full tutorial at http://gamedev.cs.colorado.edu/tutorials/Bresenham.pdf
Jose
 
 

CODE_1
GL.glBegin(GL.GL_LINES);
GL.glColor3f(0.5f,0.5f,0.0f);
GL.glVertex3f(-2.0f, 2.0f, 0.0f);
GL.glVertex3f(2.0f, -2.0f, 0.0f);
GL.glEnd();
-----------------------------------------
CODE_2
GL.glBegin(GL.GL_POINTS);
GL.glColor3f(0.5f,0.5f,0.0f);
for(int i=0; i < x; i+=2)
    GL.glVertex3f(-2.0f, 2.0f, 0.0f);
-----------------------------------------

Open in new window

0
 
david-leeAuthor Commented:
thank you for your explaining and your links.  I have a program assignment which I have to write a circle then in that circle there will be a fillled color triangle, or small circle rotating around the circle.  I am struggling with algorithm  how to fill color for triangle with polygon scan conversion method.  Can you help me on that.
0
All Courses

From novice to tech pro — start learning today.