Archive Pages Design$type=blogging

Scenery - Java OpenGL Graphics Programming

Learn OpenGL programming in java with explanation and free full source code download.

In this post we are going to learn about the Java OpenGL Graphics Programming or Java OGL Programming. Like C++ OpenGL API Library are also used in Java programming. According to Wikipedia - Java OpenGL (JOGL) is a wrapper library that allows OpenGL to be used in the Java programming language.

Opengl programming in java is compare to C++ is little bit tricky but no hard as you might think. C/ C++ are considered tougher than java, yeah they truly are. In this post we are going to learn Java OpenGL Graphics Programming. For that First we need to understand our requirements.

Prerequisite

Tools installed in your computer - 
  • Java JDK with proper path setup - Download from Oracle.
  • Java Binding for OpenGL - Downlaod it here.
  • IDE like Eclipse with OGL configured (Optional).
For learning Opengl programming in java you must have above tool properly configured. Since Eclipse is most preferred for Working in Java you might like to use it or go for other IDE. You must have the JDK configured and also the check Java OpenGL properly configured. Two folder jar and lib are most important, descriptions are given below. 

jar/ - contains all of the Java bytecode (.class files) for JOGL grouped into .JAR files.
lib/ - contains the native libraries (.so for Linux / OS X, .dll for Windows) for your platform.

About Scenery Opengl programming in java

First we need to know about what we are going to program here. We will program a simple scenery in Java Opengl. The scenery will contain the sun, sky, mountain, tree, road, cars and flag post. You can view the image below.
opengl programming in java

OpenGL in java give you power for graphics programming in java. You can make powerful Java OpenGL Graphics Programming with the use of API. 

First Step :  Create Package

First create a package name it sceneryjogl. Define the class in the package as well. 

package sceneryjogl

public class sceneryjogl{

Initialize the basic codes

Each of the Java Graphics program we will have some basic code that are required to get stated with. First you need to extend the class to proper Applet. Call the init functions and the graphics component functions as well.

Import the Java Packages

Note As you start coding you need to import java AWT and Applet and other packages, import them. Most important don't forget to import the OGL packages. Here is all the imports -

import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
import java.applet.*;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;

Extend the  Package Class

Here we will extend the main class to JApplet to our program. This help access the necessary files for graphical user interface. Also define the init function and call the paint.

public class sceneryjogl extends JApplet{

public static void main (String [] args){

}
public void init () {  

}
public void paintComponent (Graphics g) {
super.paintComponent (g);
}
}

Next Move is to fill the code. Yeah! Call the Jframe, the container give it title and other attributes to it. Initialize the component and add it to the container. "Edi Haryanto | 8011171 | Absen : 28" can be changed as you want the text to appear. The Program will exit on closing the window.

public static void main (String [] args){ 
JFrame frame= new JFrame ();
frame.setTitle("Edi Haryanto | 8011171 | Absen : 28");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JApplet applet= new sceneryjogl ();
applet.init();
frame.getContentPane().add(applet);
frame.pack();
frame.setVisible(true);
frame.setResizable(false);
}
public void init () {  
JPanel panel4 = new Panel2D ();
getContentPane().add(panel4);
}

Now we have to draw the objects. First choose the color you want to add and then fill the object with proper coordinates. Below is the code for green bushes, place the code in paintComponent. Rest of the code can be download with full source code.

//Gambar Tanaman
g.setColor(Color.green);
g.fillOval(0, 500, 30,30);
g.fillOval(25, 500, 30,30);
g.fillOval(50, 500, 30,30);
g.fillOval(15, 480, 30,30);
g.fillOval(32, 480, 30,30);
g.fillOval(90, 500, 30,30);
g.fillOval(115, 500, 30,30);
g.fillOval(140, 500, 30,30);
g.fillOval(105, 480, 30,30);
g.fillOval(122, 480, 30,30);
g.fillOval(180, 500, 30,30);
g.fillOval(205, 500, 30,30);
g.fillOval(230, 500, 30,30);
g.fillOval(195, 480, 30,30);
g.fillOval(212, 480, 30,30);
g.fillOval(270, 500, 30,30);
g.fillOval(295, 500, 30,30);
g.fillOval(320, 500, 30,30);
g.fillOval(285, 480, 30,30);
g.fillOval(302, 480, 30,30);
g.fillOval(510, 500, 30,30);
g.fillOval(535, 500, 30,30);
g.fillOval(560, 500, 30,30);
g.fillOval(525, 480, 30,30);
g.fillOval(542, 480, 30,30);
g.fillOval(600, 500, 30,30);
g.fillOval(625, 500, 30,30);
g.fillOval(650, 500, 30,30);
g.fillOval(615, 480, 30,30);
g.fillOval(632, 480, 30,30);
g.fillOval(690, 500, 30,30);
g.fillOval(715, 500, 30,30);
g.fillOval(740, 500, 30,30);
g.fillOval(705, 480, 30,30);
g.fillOval(722, 480, 30,30);
g.fillOval(780, 500, 30,30);
g.fillOval(805, 500, 30,30);
g.fillOval(830, 500, 30,30);
g.fillOval(795, 480, 30,30);
g.fillOval(812, 480, 30,30);
g.fillOval(870, 500, 30,30);
g.fillOval(895, 500, 30,30);
g.fillOval(920, 500, 30,30);
g.fillOval(885, 480, 30,30);
g.fillOval(902, 480, 30,30);
g.fillOval(960, 500, 30,30);
g.fillOval(985, 500, 30,30);
g.fillOval(1010, 500, 30,30);
g.fillOval(975, 480, 30,30);
g.fillOval(992, 480, 30,30); 

Similarly other objected can be painted using the paint. Download the whole source code for this Java OpenGL Graphics Programming and share you views. If you have any doubt don't hesitate to put your comment and ask the same. Keep learning!

Download the Source file -  Name it as java file and run on your computer.

COMMENTS

Name

3D Bi-Cycle 3D Game 3D Laptop 3D Objects 3D Projects 3D Zoo Algorithm Android Aquarium Bellman-Ford Algorithm Block Breaker Blockshooting Bucket Sort C# Chess Clock Code Blocks Colors Complex Project Complex Projects Crab Pong Cross Zero DSAV Escapa First Come First Serve Fluids Font Demo Games Gear Motion GlutDino Glutplane Graphics Editor iOS iPhone Java Java OpenGL Graphics Programming Light Torus Linked List Ludo Board Game Mancala board games Memory blocks game Memory Game Menu Mickey Mouse Minesweeper Miniature Steam Engine moth Motion Blur MoveLight moving car Moving Ship Multiplex Networking Based Project Nuclear Power Plant Olympic opengl c++ examples OpenGL ES OpenGL Tutorial Origami OS Based Projects Paint Paper Folding Particles Drop Path Finding ping pong Pong Game Project Report Projects Report Puzzles qix like Random Flowing lines Rigid Body Rings Robot sample c++ opengl code Screen Saver Screen Saver Ship Shadow Cube Shadowfun Ship Iceberg Simple Drawing Simple Haloed Lined Wireframe Simple Move Light Simple Project Simulation SNAKE XENZIA GAME Solar system Sorting Sphere Spot Light Swing Stars Taj Mahal The Edge Game Tic Tac Toe Tower of Hanoi Traffic Signal Transformation Triangular Animation Tutorial water ripple effects Whirlpool
false
ltr
item
OpenGL Projects: Scenery - Java OpenGL Graphics Programming
Scenery - Java OpenGL Graphics Programming
Learn OpenGL programming in java with explanation and free full source code download.
http://4.bp.blogspot.com/-p7fmdUPXYwk/VlSkLkb-x3I/AAAAAAAAHgI/VLucZykaBh0/s400/download.png
http://4.bp.blogspot.com/-p7fmdUPXYwk/VlSkLkb-x3I/AAAAAAAAHgI/VLucZykaBh0/s72-c/download.png
OpenGL Projects
http://www.openglprojects.in/2015/11/java-opengl-graphics-programming.html
http://www.openglprojects.in/
http://www.openglprojects.in/
http://www.openglprojects.in/2015/11/java-opengl-graphics-programming.html
true
2020194800836807725
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago