Wednesday, December 21, 2016

Bicycle Riding

Copyright rests with the author Muhammed Tariq Siddiqui at the following site(Planet-source-code).

I ran the program and found out it requires no modification to run in ubuntu.

SnapShot:



This program has used quadric surfaces such gluDisk, gluCylinder and gluSphere which are tesselations of disks and partial disks or arcs.

Tuesday, November 1, 2016

Conway's Game of Life

Conway was interested in a problem presented in the 1940s by mathematician John von Neumann, who attempted to find a hypothetical machine that could build copies of itself and succeeded when he found a mathematical model for such a machine with very complicated rules on a rectangular grid. The Game of Life emerged as Conway's successful attempt to drastically simplify von Neumann's ideas. The game made its first public appearance in the October 1970 issue of Scientific American, in Martin Gardner's "Mathematical Games" column. From a theoretical point of view, it is interesting because it has the power of a universal Turing machine: that is, anything that can be computed algorithmic-ally can be computed within Conway's Game of Life.

The rules of the game can be found all around the Internet. I have created a mesh of cells with randomly assigned values of alive or dead. Then iterated thorugh the mesh of cells and toggled according to the rules.

Snapshot:



Here is the source.
I could have easily thought about making this game of life in Javascript which would be like click on a few squares in the blog and just click play to see the result.. I thought that would be taxing on the minds so let this random generation be.

Saturday, October 29, 2016

Image Editing Using GIMP

You may have seen outputs of a few of the projects in the past. I have created this 640x480 image using GIMP. Graphical Image Manipulation Tool allows you to work with layers and create appealing posters or banners. If you are new to graphics this is the place to start your work in it.

Created this picture:


As can be seen... these images were opened as layers scaled,rotated,sheared and translated and blended with other layers with different opacity and blending mode while merging. All these are skills you could hone to make a living as a graphic designer.

Contractive Affine Transformations

It is too much of an effort to reproduce the theory behind this but suffice is to give a link to this page and this page. Now I will show you a C-curve I produced using a method called contractive affine transformation in Java OpenGL.

Snapshot:

A small change in the iteration can produce the Dragon curve:
 The change is in the display function:
gl.glBegin(GL2.GL_POINTS);
    for(int i=0;i<100000;i++)
    {
        switch(rand.nextInt(2))
        {
        case 0:
            x1=(x+y)*0.5f;
            y=(-x+y)*0.5f;

            x=x1;
            break;
        case 1:
            x1=(-x+y)*0.5f+1;
            y=(-x-y)*0.5f;

            x=x1;
            break;
        }
        gl.glVertex2f(x, y);
    }
Snapshot:

Here is the source for the C curve.
Another modification I thought would be useful is the fractal "Scroll".
Snapshot:

This is the code to generate it:
 gl.glBegin(GL2.GL_POINTS);
    for(int i=0;i<100000;i++)
    {
        switch(rand.nextInt(2))
        {
        case 0:
            x1=0.693f*x-0.4f*y;
            y=0.4f*x+0.693f*y;

            x=x1;
            break;
        case 1:
            x1=0.346f*x+0.2f*y+0.693f;
            y=-0.2f*x+0.346f*y+0.4f;

            x=x1;
            break;
        }
        gl.glVertex2f(x, y);
    }
    gl.glEnd();

Friday, October 21, 2016

CUDA bit-reverse template demo

I have Nvidia GEFORCE with CUDA graphics card with the 410M processor. I suppose this configuration is the oldest processor in the NVidia family of graphics cards. I feel I am lucky as I had this processor shipped in my laptop by sheer serendipity. I happen to know a little bit of game programming so would like to try my luck at developing with CUDA. It is a parallel computing platform and programming model. When Nvidia introduced CUDA it stood for compute unified device architecture.

I researched a bit on installing Nvidia CUDA and found that first Nvidia drivers need to be installed(which were'nt there). Then I installed the CUDA 5.5 toolkit. I chose the 5.5 version because my Ubuntu 14.04 LTS version with Nvidia GEFORCE 410M processor would only support that version of toolkit.

After much helter-skelter I found that you could not do programming with CUDA in normal eclipse. You needed the Nsight Eclipse. I downloaded all of these and finally I was ready to run a CUDA program. Found that C programs in CUDA have .cu extension.
Went to file-> New Project-> CUDA C/C++ Project
Gave a name to the project.
In the next screen let the defaults as it is:
In the next screen clicked finish.
Then right clicked on the project name->New->Source File
Then in the interface give a name to the file with .cu extension. You may choose any template of your choice and as I am new to CUDA I just let the default as it is(Bit-reverse demo template). With this basic experience in running a bit reverse program whose output looks like
Input value: 0, device output: 0, host output: 0
Input value: 1, device output: 128, host output: 128
Input value: 2, device output: 64, host output: 64
Input value: 3, device output: 192, host output: 192
Input value: 4, device output: 32, host output: 32
Input value: 5, device output: 160, host output: 160
Input value: 6, device output: 96, host output: 96
Input value: 7, device output: 224, host output: 224
Input value: 8, device output: 16, host output: 16
Input value: 9, device output: 144, host output: 144
Input value: 10, device output: 80, host output: 80
Input value: 11, device output: 208, host output: 208
Input value: 12, device output: 48, host output: 48
Input value: 13, device output: 176, host output: 176
Input value: 14, device output: 112, host output: 112
.
.
(so on upto 255)
I was a bit encouraged to try and develop parallel fast games using CUDA.
Wondering what this device and host mean. To hazard a guess the device means the Graphics card and the host means the Main CPU. Feeling too tired to try and understand the code. I hope you understood what the program does.
If interested you can download the program from here. Thank You :-)
Update:
Something says me to develop this project further. I am looking to parallelize some of the games that make use of the CPU so that they run faster. For the present my interest is in rendering fast the shadow polygons in the scene, I heard this requires significant computational overhead and existing algorithms are not good enough.

Sunday, October 16, 2016

Noisy texture to a polygon using procedural noise

It is very easy to generate noise using methods mentioned in this site. By using functions smoothNoise, turbulence etc mentioned in the site, It was quite straight--forward to generate the following noisy texture. I am doing this in Java- bindings for OpenGL.

Snapshot:


Here is the source.

Further modification of the program to generate textures such as mixture of sin wave and noise as mentioned in the same site gave the following result.

Snapshot:


The modification in the above program was replacing turbulence function by:

 for (int y = 0; y < 128; y++) {
            for (int x = 0; x < 128; x++) {
                // to do use a formula here to create a texture
                value=(1 + Math.sin( (x + turbulence((double)x ,(double) y,64 ) / 2 ) * 50) ) / 2;
                int red=(int)((0xff)*value);
                int green=(int)((0xff)*value);
                int blue=(int)((0xff)*value);//*(x^y);
                buffer.put((byte) ((0xFF)&red));     // Red component
                buffer.put((byte) ((0xFF)&green));      // Green component
                buffer.put((byte) ((0xFF)&blue));               // Blue component
                buffer.put((byte) (0xFF));    // Alpha component. Only for RGBA
            }
        }

in the init function.
The explanation in the site upvector.com is much clearer and you can refer that as well.


Similarly the following formula(done in a different way) for value yields this pattern:

xyValue = x * xPeriod / noiseWidth + y * yPeriod / noiseHeight + turbPower * turbulence(x, y, turbSize);
value = (1+Math.sin(xyValue * 3.14159))/2;
Where the following variables have to be defined before hand:
           //xPeriod and yPeriod together define the angle of the lines
           //xPeriod and yPeriod both 0 ==> it becomes a normal clouds or turbulence pattern
           double xPeriod = 5.0; //defines repetition of marble lines in x direction
           double yPeriod = 10.0; //defines repetition of marble lines in y direction
           //turbPower = 0 ==> it becomes a normal sine pattern
           double turbPower = 5.0; //makes twists
           double turbSize = 32.0; //initial size of the turbulence

With these variables the following wooden texture was obtained:

double xyPeriod = 12.0; //number of rings
double turbPower = 0.1; //makes twists
double turbSize = 32.0; //initial size of the turbulence
And in the loop:
                double xValue = (x - noiseWidth / 2) / (double)(noiseWidth);
                double yValue = (y - noiseHeight / 2) / (double)(noiseHeight);
                double distValue = Math.sqrt(xValue * xValue + yValue * yValue) + turbPower * turbulence(x, y, turbSize);
                double sineValue = Math.sin(2 * xyPeriod * distValue * 3.14159);
               
                int red=(int)(0xff+(0xff)*sineValue);
                int green=(int)((0x20)*sineValue);
                int blue=(int)((0x20));//*(x^y);
                buffer.put((byte) ((0xFF)&red));     // Red component
                buffer.put((byte) ((0xFF)&green));      // Green component
                buffer.put((byte) ((0xFF)&blue));               // Blue component
                buffer.put((byte) (0xFF));    // Alpha component. Only for RGBA

Here is the texture output:

Wednesday, September 28, 2016

Play a video or video capture of webcam - texture on cube #OpenGL #OpenCV

Just visit this awesome site where there is this awesome code which needed a few modifications to play back any video or capture video from the webcam. Now you won't believe this but it was as simple as that. With OpenCV I feel I just turned a pro.

Snapshot:


The mouse can be used as a trackball and you can rotate the scene which consists of a cube on both sides of which texture of video frames is mapped. That snapshot was not still image, it is me sitting in front of the computer poring over the monitor.

Monday, September 26, 2016

Add an image opened using #OpenCV as a texture in OpenGL

Image result for what is OpenCVI was toying with OpenCV since a long time. Here is a tutorial on how to download and configure eclipse for OpenCV. OpenCV (Open Source Computer Vision) is a library of programming functions mainly aimed at real-time computer vision. Originally developed by Intel's research center in Nizhny Novgorod (Russia), it was later supported by Willow Garage and is now maintained by Itseez.

In this C++ project in Eclipse an image is opened using imread method of OpenCV tool and the opened image is used as a texture to map to a polygon drawn across the screen. Actually this image in the window is itself a snapshot of another program which does texture mapping inside a 3D house scene program. I could have chosen any other image.

Snapshot:

Here is the source.

Sunday, September 18, 2016

#JOGL Various Textures to Polygons

Some textures of size 10 x 10 have been created from scratch using formulas such as

//Use this formula to create texture in the program- Tex1
int red=(0xff)*(x%2);
int green=(0xff)*(y%2);
int blue=(0xff);//*(x^y);

Resulting Snapshot:

//Use this formula to create texture in the program- Tex2
int red=(int)((0xff)*Math.sin(10*x*Math.PI/180));
int green=(0xff);
int blue=(0xff);
Resulting Snapshot:                       
Going any further I feel would kill your drive to do something yourself and get exhilarating textures. So I hope I have shown the way to create beautiful patterns with sin,cos,modulus and other mathematical operations.

If you are knowledgeable about MipMaps and filtering in jogl then you may note that I have used following Magnification filter.

gl2.glTexParameteri(GL2.GL_TEXTURE_2D,GL2.GL_TEXTURE_MAG_FILTER,GL2.GL_NEAREST);

Here is the source which you can modify and tinker.

Next goal is to  use procedural methods to generate textures as mentioned in the site here.

A textile manufacture in my area Apsara silks is featured here in this article on https://www.indiantextilemagazine.in/apsara-silks-exploring-new-frontiers-to-stay-ahead/
I infact had an appointment with Mr goenka that I didn't keep up with. It was supposed to be a website that this manufacturer wanted to setup. All talk of industry academia tieup is hocus pocus as academia is a lot poorer and industry indifferent. So if you want more stupidity than skipping appointments you could always conjure up websites that let you design a pattern and get the digital print on fabric of your choice within days if not weeks.

#JOGL Lighting - An Animation

In this project the light source is moving in a circular path around the eight spheres. The position of GL_LIGHT0 is changed by a call to the method glLightfv().

Snapshot(GIF):

Here is the source.

#JOGL Setting Material Properties

In this program LIGHTING has been enabled and the material properties have been set.
A glutSolidSphere() has been drawn eight times each time the SHININESS component has been increased by 16.
Snapshot:

Here is the source.

Friday, September 9, 2016

#JOGL Cubes with Vertex Arrays

Here is a simple program to draw a cube with vertex arrays that is shared as a demo program by the author David J Eck in his site of Hogwarts and William Smith college.

I am sharing this program as is and all copyrights rest with the original author.

Snapshot:


Here is the source.

#JOGL Program to create and apply a one dimensional texture on a cube

In this program I am applying a one dimensional texture on a cube.

Snapshot:


Here is  the source.

#JOGL Applying texture to polygon created from a byte array

Here I am applying a texture to the polygon after creating the texture from a byte buffer. A variety of textures can be created this way.

Snapshot:


Here is the source. A few modifications to this program allows you to create different textures by just changing the formula. Here is the same program with variety of textures mentioned as formulas.

#JOGL A simple program to apply a texture to cube faces and rotate the cube

This program not only texture is applied to a cube but the cube is made to rotate on pressing the arrow keys.

Snapshot:


Here is the code.

#JOGL A simple program to apply texture(image) to a polygon

A simple program in Java bindings for OpenGL where I apply a texture to a square(polygon). The texture is imported from an image file. The image is of a cartoon character Jerry whom i like very much. I like other characters too like tom and the dog.

Snapshot:


Here is the code.

#JOGL A simple Paddle Wheel

In this program, which the author David J Eck describes as a simple 3D program(chapter: Geometry) in his graphics book, a paddle wheel is being drawn. We can define a polygon in the x-y plane above the x axis and rotate it wrt the x axis each time with varying angles. Then to get a 3D look we tilt the paddle wheel by rotating about y axis.

Snapshot:


Here is the source.

#JOGL Simple program to draw a triangle using a display list

In this simple program a triangle is being drawn using a display list. The display list is identified by an integer. The integer is generated by call to glGenLists(). Then calls to glNewList() and glEndList() defines the list. Finally a call of glCallList() is made to draw whatever has been defined in the display list.
Snapshot:
Here is the source.

#JOGL Simple Program to draw a Triangle and rotate it about z-axis

Although the use of JPanel and calling repaint method on it is a good way to draw in Java Bindings for OpenGL I have followed the other method of creating a GLCanvas object and adding it to the JFrame object. In this program I have created a basic frame which sets the background color to red and clears the canvas and then draws a triangle. Each time the display is called by the FPSAnimator object the triangle is drawn at a new position after rotation by an angle. Angle is incremented in the display function itself.

Snapshot:

Here is the source in case you are interested to know.

Friday, September 2, 2016

Translate a Circle by pressing Swing Class JButton in #JOGL

This program translates the circle on pressing the translate button.


Here is the source:(online Viewing)


import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;

import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.awt.GLJPanel;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

class CircleTranslate extends GLJPanel implements GLEventListener,ActionListener {

/**
 * Interface to the GLU library.
 */
private GLU glu;
int x,y;
static JButton okButton;
/**
 * Take care of initialization here.
 */


CircleTranslate()
{
// super(g);
super( new GLCapabilities(null) ); // Makes a panel with default OpenGL "capabilities".
GLJPanel drawable = new GLJPanel();               // new GLJPanel inside GLJPanel
drawable.setPreferredSize(new Dimension(200,100));
setLayout(new BorderLayout());
add(drawable, BorderLayout.CENTER);
drawable.addGLEventListener(this); // Set up events for OpenGL drawing!
// drawable.addMouseListener(this);
//drawable.addMouseMotionListener(this);
//drawable.addActionListener(this);

}

public void actionPerformed(ActionEvent e) {
// System.exit(0);
x++;
repaint();
}
public void init(GLAutoDrawable gld) {
    GL2 gl = gld.getGL().getGL2();
    glu = new GLU();

    gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
//    gl.glViewport(-250, -150, 250, 150);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluOrtho2D(-250.0, 250.0, -150.0, 150.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    x=10;y=30;
    repaint();
}

/**
 * Take care of drawing here.
 */
public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
    /*
     * put your code here
     */
   
    drawCircle(gl, x, y, 50);
}

public void reshape(GLAutoDrawable drawable, int x, int y, int width,
        int height) {
}


private void drawCircle(GL2 gl, int x1, int y1, int r) {
    gl.glPointSize(1.0f);
    gl.glBegin(GL2.GL_POINTS);
   
    int x=0,y=r,p=1-r;
    while(x<y)
    {
   
    if(p<0)
    p+=2*x+3;
    else {
    p+=2*(x-y)+5;
    y--;
    }
    x++;
    circleSymmetry(gl,x1,y1,x,y);

    }
    gl.glEnd();//end drawing of points

}
public void dispose(GLAutoDrawable arg0)
{
}
public void circleSymmetry(GL2 gl,int xc,int yc,int x,int y)
{
gl.glVertex2i(xc+x , yc+y );
gl.glVertex2i(xc-x , yc+y );
gl.glVertex2i(xc+x , yc-y );
gl.glVertex2i(xc-x , yc-y );
gl.glVertex2i(xc+y , yc+x );
gl.glVertex2i(xc+y , yc-x );
gl.glVertex2i(xc-y , yc+x );
gl.glVertex2i(xc-y , yc-x );
}
public static void main(String args[])
{
JFrame window = new JFrame("Circle Translate");
    // The canvas
    CircleTranslate panel = new CircleTranslate();
    panel.setPreferredSize(new Dimension(1000,1000));      
    okButton = new JButton("Translate");
    JPanel content = new JPanel();

content.setLayout(new BorderLayout());
content.add(panel, BorderLayout.CENTER);
content.add(okButton, BorderLayout.SOUTH);
    okButton.addActionListener(panel);
   
    window.setContentPane(content);
    window.pack();
    window.setLocation(0,0);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setVisible(true);
    panel.requestFocusInWindow();
}
}
Thanks!!!

Friday, July 22, 2016

Simple program to create JFrame and add a JPanel to it and draw using Graphics class in Java

This program is self explanatory...

I have done this to demonstrate simple way of creating A window(using Java Swing) and display something inside a panel in it.

/* Program to display a rectangle, filled rectangle and a line all with different colors
 * and a text string
 */
import java.awt.Graphics;
import java.awt.Color;
//import java.awt.
import java.awt.event.*;
import javax.swing.JPanel;
import javax.swing.JFrame;
//import javax.swing.Timer;
public class FirstJavaGraphics extends JPanel
{
   
public static void main(String[] args)
{
    FirstJavaGraphics fjg=new FirstJavaGraphics();
    JFrame window=new JFrame("Hello Java Graphics");
    window.setSize(640, 480);
    window.add(fjg);
    window.setVisible(true);
}
public void paintComponent(Graphics g)
{
    super.paintComponent(g);
    setBackground(Color.RED);
    g.drawRect(100, 20, 30, 30);
    g.setColor(Color.GREEN);
    g.fillRect(200, 320, 40, 40);
    g.drawLine(100, 100, 200, 200);
    g.setColor(Color.BLUE);
    g.drawString("Hello WOrld", 100, 250);
}
FirstJavaGraphics()
{
}
}

Snapshot:

The next program will be to animate the scene using a Timer in the swing package.

Monday, July 11, 2016

#JOGL-Events- Mouse and Keyboard handling using (immediate mode) animator class

These two programs I consider basic in handling mouse and keyboard events. I looked up some programming sites and had to collate info from variety of sources. If you are new to JOGL then I suggest you this site where you can download a PDF of e-book on computer graphics by David J Eck.

The first program i made was to handle keyboard events:
Here it is:
import java.awt.*;
import java.awt.event.*;

import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.gl2.*;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.glu.GLU;

import javax.swing.JFrame;

class mykeyboardeventshandler implements KeyListener,GLEventListener
{
String msg="";
int x=10,y=20;
private GLU glu;
public void keyPressed(KeyEvent ke)
{
//showStatus("Key down");
}
public void keyReleased(KeyEvent ke)
{
//showStatus("Key released");
}
public void keyTyped(KeyEvent ke)
{
msg+=ke.getKeyChar();
//repaint();
}
/**
 * Take care of initialization here.
 */
public void init(GLAutoDrawable gld) {
    GL2 gl = gld.getGL().getGL2();
    glu = new GLU();

    gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    gl.glViewport(-250, -150, 250, 150);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluOrtho2D(-250.0, 250.0, -150.0, 150.0);
}

/**
 * Take care of drawing here.
 */
public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
    /*
     * put your code here
     */
//    drawLine(gl, 0, 0, 100, 50);
    gl.glPushMatrix();
    GLUT glut = new GLUT();
    gl.glRasterPos2i(0,10);
  //  gl.glTranslatef(0, 0, 0);
    gl.glColor3f(1, 0, 0);
    glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, msg);
    gl.glPopMatrix();
    gl.glFlush();
}

public void reshape(GLAutoDrawable drawable, int x, int y, int width,
        int height) {
}
public void dispose(GLAutoDrawable arg0)
{
}
}
public class keyboardeventsdemo
{
    public static void main(String[] args)
    {
    //getting the capabilities object of GL2 profile
    final GLProfile profile=GLProfile.get(GLProfile.GL2);
    GLCapabilities capabilities=new GLCapabilities(profile);
    // The canvas
    final GLCanvas glcanvas=new GLCanvas(capabilities);
    final Animator animator = new Animator(glcanvas);
    mykeyboardeventshandler b=new mykeyboardeventshandler();
    glcanvas.addGLEventListener(b);
    glcanvas.addKeyListener(b);
    glcanvas.setSize(400, 400);
    //creating frame
    final JFrame frame=new JFrame("Basic frame");
    //adding canvas to frame
    frame.add(glcanvas);
    frame.setSize(640,480);
    frame.setResizable(false);
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            animator.stop();
            frame.dispose();
            System.exit(0);
        }
});
    animator.start();
    frame.setVisible(true);
    glcanvas.requestFocus();
    }
}



Snapshot:
 
The second program i made is on handling mouse events. I made a separate class for handling mouse events and GLEvents called MyMouseEventsHandler. I instantiate it in the MouseEventsDemo class and them add event listeners to the frame using this object.

import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.util.gl2.GLUT;
import com.jogamp.opengl.util.Animator;
import java.awt.*;
import java.awt.event.*;

import javax.swing.JFrame;

class MyMouseEventsHandler implements MouseMotionListener, MouseListener,GLEventListener
{
String msg="hello";
int mouseX=0,mouseY=0;
private GLU glu;
public void init()
{
}
public void mouseClicked(MouseEvent me)
{
mouseX=0;
mouseY=10;
msg="mouse clicked";
//repaint();
}
public void mouseEntered(MouseEvent me)
{
mouseX=0;
mouseY=10;
msg="mouse Entered";
//repaint();
}
public void mouseExited(MouseEvent me)
{
mouseX=0;
mouseY=10;
msg="mouse Exited";
//repaint();
}
public void mousePressed(MouseEvent me)
{
mouseX=0;
mouseY=10;
msg="mouse Pressed";
//repaint();
}
public void mouseReleased(MouseEvent me)
{
mouseX=me.getX();
mouseY=me.getY();
msg="Mouse Released";
//repaint();
}
public void mouseMoved(MouseEvent me)
{
//showStatus("Moving mouse at "+me.getX()+" , "+me.getY());
}
public void mouseDragged(MouseEvent me)
{
mouseX=me.getX();
mouseY=me.getY();
msg="mouse dragged";
//repaint();
}
public void init(GLAutoDrawable gld)
{
    GL2 gl = gld.getGL().getGL2();
    glu = new GLU();

    gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    gl.glViewport(-250, -150, 250, 150);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluOrtho2D(-250.0, 250.0, -150.0, 150.0);
}
public void display(GLAutoDrawable gld)
{
    GL2 gl = gld.getGL().getGL2();
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
    /*
     * put your code here
     */
//    drawLine(gl, 0, 0, 100, 50);
    gl.glPushMatrix();
    GLUT glut = new GLUT();
    gl.glRasterPos2i(0,10);
  //  gl.glTranslatef(0, 0, 0);
    gl.glColor3f(1, 0, 0);
    glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, msg);
    gl.glPopMatrix();
    gl.glFlush();
//    gld.swapBuffers();
}
public void reshape(GLAutoDrawable gld,int x,int y,int width,int height)
{
   
}
public void dispose(GLAutoDrawable gld)
{
   
}
}
public class MouseEventsDemo extends JFrame
{
    public static void main(String[] args)
    {
        final GLProfile profile=GLProfile.get(GLProfile.GL2);
        GLCapabilities capabilities=new GLCapabilities(profile);
        // The canvas
        final GLCanvas glcanvas=new GLCanvas(capabilities);
        MyMouseEventsHandler mmeh=new MyMouseEventsHandler();
        final Animator animator = new Animator(glcanvas);
//        glcanvas.addGLEventListener(mmeh);
        glcanvas.setSize(400, 400);
        //creating frame
        final JFrame frame=new JFrame("Basic frame");
        //adding canvas to frame
        frame.add(glcanvas);
        frame.setSize(640,480);
      
        frame.setResizable(false);
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                animator.stop();
                frame.dispose();
                System.exit(0);
            }
});
         glcanvas.addGLEventListener(mmeh);
        glcanvas.addMouseMotionListener(mmeh);
        glcanvas.addMouseListener(mmeh);
        animator.start();
        frame.setVisible(true);
      
        glcanvas.requestFocus();
      
    }
}

 Snapshot:

 

Saturday, June 25, 2016

#JOGL DDA, Bresenhams, Mid-Point Circle and Mid-Point Ellipse Algorithms

I have implemented the above mentioned algorithms using Java Bindings for OpenGL.

Snapshots and Code:
Bresenhams: Code
Mid-Point Circle: Code
 DDA:Code
Ellipse: Code

Monday, May 30, 2016

#JOGL My First OpenGL program in Java

I recently got an interview call for a requirement for high end graphics(CUDA etc), with strong skills in java, hadoop and knowledge of spark were added advantages. It is very clear that java, python and more modern languages are the future of graphics.
I learn't that Java is gaining popularity in writing games in OpenGL. I am now forced to work on Java now that my college has made a switch to OpenGL using Java. So Bye-Bye-C. The ultimate goal of shifting to java is obviously to develop android games. OpenGL ES which stands for OpenGL for Embedded Systems (or GLES) is a subset of the OpenGL computer graphics rendering application programming interface (API) for rendering 2D and 3D computer graphics such as those used by video games, typically hardware-accelerated using a graphics processing unit (GPU).
My first program using JOGL draws a red polygon and a green line.

Here is a snapshot:

Here is the source.

Sunday, May 8, 2016

Rain Water Harvesting

RWH:-
In this project rain water is collected from roof tops and is stored in under ground tanks after purification and is pumped out for domestic and garden use.

Snapshot:






Here is the source.

Thursday, April 28, 2016

Calendar

This project is about a calendar which displays the various dates from 1 to 31 and the weekdays(Sun to Sat).
The project can be modified to select a particular month or year of the calendar on mouse input. This is left as an exercise.

Snapshot:


Here is the source.

Galaxy and cylinder

Two projects in this post. The first one is on Galaxy where the points(stars) are moving towards the viewer or looks like the space ship is moving in an infinite star system.
Snapshot:


Here is the source.

The other project is about a group of points in a cylinder rotating about the axis of the cylinder...

Snapshot:


Here is the source.

Friday, April 22, 2016

Vehicles going down a Highway - A Racing Game

I happen to travel daily on a tolled highway and this has afforded me some insight into the way vehicles move on it.
To the uninitiated in graphics simulating a highway with vehicles of all sizes would seem trivial.


A Question:
A question occurred to me about how could a vehicle try to minimize its travel time?

Observations:
Heavy vehicles struggle to climb an uphill and it also depends on whether the truck is carrying goods or not. Under such circumstances other passenger vehicles cannot get passage if the slow moving vehicles block the way.

Another observation is travel time depends not only on the top speed of your vehicle but also on the speed and position of other vehicles on the way and this is something that cannot be predicted.

Your own vehicle sometimes moves faster and sometimes slower depending on road conditions. Racing car fans know very well how fractions of a second matter in a win or loss.

The solution: 
The vehicles going on the road would do better for themselves if they stick to certain policies. These rules of driving do not originate from safety or traffic rule considerations but from game theory. What might be the form of such rules? Why would they help you while driving on a highway? Are there vast number of such rules, all of which you could never remember and more importantly would, not obeying them lead to any penalties in travel time.
I have read that in game theory a zero sum game is one where losses made by a player are exactly the gains made by the other and vice-versa. In a zero sum game which is also called strictly competitive game, solutions are usually found by the minimax algorithm a technique which assigns a score to each player and tries to attain maximum score for "the" player as opposed to the competitor under any circumstance.

I have in mind making an unbeatable tic-tac-toe game of 3x3 or 4x4 or 5x5 and this blog post originated from that thought.

Tuesday, April 19, 2016

Stack and Queue

On request i have created a project called Stack and Queue in which the following classes are defined.

button
stack
queue

There are four buttons at the bottom named "Push" "Pop" "Insert" and "Delete" which are used to push and pop from the stack and insert and delete from the queue.

Here is a snapshot:


Here is the source. Remember it is a C++ project and you have to save the file as .cpp. This is a very easy project to understand as you would have studied the working of stack and queue in your data structure classes.

Tuesday, March 29, 2016

Kaleidoscope - a visual treat

I am trying to generate views like these:....


These images do look beautiful don't they?



I am poring over books on symmetry by Marcus Du Sautoy(Finding Moonshine) etc. 


Students of high schools such as you may create a great project out of printing these kind of patterns using your father's newly acquired laser printer.


And this one is beautiful too....



Finally last but not the least some pattern of tiles from the alhambra, Granada, Andalusia, Spain...
This one is a triangular pattern of tiles...


Can't make out this one and it is taken from some university's mathematics site... They must have found something truly amazing in these patterns.


So you must be wondering when is my project output coming... Hold your breath... I have not started work yet.
Effort put into this project would be considerable I guess. I propose to use symmetry and generate patterns by randomly generating one pattern of polygons in a part of the image and reflecting/tiling it to other parts. It looks daunting but doable. If i generate a polygon in one region and reflect it in other parts using symmetry the problem is how will I fill it. The vertices may not be in order and the polygon may be self intersecting. Will keep everyone updated in this page.