NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package cse423lab2;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/


import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;

/**
*
* @author sbiswas.amit
*/
public class DDALines implements GLEventListener {
/**
* Interface to the GLU library.
*/
private GLU glu;

/**
* Take care of initialization here.
* @param gld
*/
@Override
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.
* @param drawable
*/
@Override
public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();

gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
/*
* put your code here
*/
DDA(gl, 0.0f, 0.0f, 0.0f, 50.0f);
DDA(gl, 0.0f, 50.0f, 50.0f, 0.0f);
DDA(gl, 0.0f, 0.0f, 50.0f, 0.0f);

}

@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
//do nothing
}

public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
//do nothing
}

private void DDA(GL2 gl, float x1, float y1, float x2, float y2) {
//write your own code


gl.glPointSize(1.0f);
gl.glColor3d(1, 0, 0);
gl.glBegin(GL2.GL_POINTS);


gl.glVertex2f(x1, y1);

float len;
float xc,yc;
float dy = y2-y1;
float dx = x2-x1;
float m = dy/dx;
float adx = Math.abs(dx);
float ady = Math.abs(dy);

if(adx>=ady) {
len = adx;
} else {
len = ady;
}

dx = dx/len;
dy = dy/len;

xc = x1 + 0.5f*Sign(dx);
yc = y1 + 0.5f*Sign(dy);

int i=0;
while(i<=len) {
gl.glVertex2f(xc, yc);
xc = xc+dx;
yc = yc+dy;
i++;
}


gl.glVertex2f(x2, y2);
gl.glEnd();
}

public int Sign(float x) {
if(x<0) {
return -1;
} else if(x==0) {
return 0;
} else {
return 1;
}
}

public void dispose(GLAutoDrawable arg0) {
//do nothing
}
}

package cse423lab2;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

//com.jogamp or javax.media
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.JFrame;
/**
*
* @author sbiswas.amit
*/
public class OpenGL {

/**
* uses point drawing DDA algorithm
**/
/*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);
ThirdGLEventListener b =new ThirdGLEventListener();
glcanvas.addGLEventListener(b);
glcanvas.setSize(400, 400);
//creating frame
final JFrame frame = new JFrame("My frame");
//adding canvas to frame
frame.add(glcanvas);
//frame.setSize(640,480);
frame.setSize(frame.getContentPane().getPreferredSize());
frame.setVisible(true);
}*/

/**
* uses line drawing method
**/
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);
DDALines drawing = new DDALines();
glcanvas.addGLEventListener(drawing);
glcanvas.setSize(400, 400);

//creating frame
final JFrame frame = new JFrame ("straight Line");

//adding canvas to frame
frame.getContentPane().add(glcanvas);
frame.setSize(frame.getContentPane().getPreferredSize());
frame.setVisible(true);

}

}



     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.