Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7643479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:27:36+00:00 2026-05-31T09:27:36+00:00

The exercise I have is the following: In display() add a method drawLine. Probably,

  • 0

The exercise I have is the following:
In display() add a method drawLine. Probably, you will need something like
drawLine(GL gl, int x1, int y1, int x2, int y2)
now using the equation of a line, plot the individual points that make up the line from x1,y1 to x2,y2 in JOGL
using (for instance) gl.glPointSize(1.0f); gl.glBegin(GL.GL_POINTS);
If you have coloured the points white, and used the following projections

gl.glViewport(-250, -150, 250, 150);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluOrtho2D(-250.0, 250.0, -150.0, 150.0);

then with a value of a line from points (0,0) to (100,100) yours will look
something like the following picture:

enter image description here

My code so far for the EventListener where I create my line is the following:

import javax.media.opengl.*;
import javax.media.opengl.glu.GLU;


public class ThirdGLEventListener implements GLEventListener {

/**
 * Interface to the GLU library.
 */
private GLU glu;

/**
 * Take care of initialization here.
 */
public void init(GLAutoDrawable gld) {
    GL gl = gld.getGL();
    glu = new GLU();

    gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);


    gl.glViewport(-250, -150, 250, 150);
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluOrtho2D(-250.0, 250.0, -150.0, 150.0);
}

/**
 * Take care of drawing here.
 */
public void display(GLAutoDrawable drawable) {



    GL gl = drawable.getGL();

    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    /*
     * put your code here
     */

    drawLine(gl, 0, 0, 100, 100);

}

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

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

private void drawLine(GL gl, int x1, int y1, int x2, int y2) {
    gl.glPointSize(1.0f);
    gl.glBegin(GL.GL_POINTS);

    // This is where the whole problem lies. 

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

}

}

My problem is that I don’t quite know how to complete the code inside the method for the line equation. I would appreciate it if you could help me with that bit. I think the rest of it is just right, I just need to find how to implement the line equation inside the drawLine() method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:27:37+00:00Added an answer on May 31, 2026 at 9:27 am

    Try using GL_LINES:

    private void drawLine(GL gl, int x1, int y1, int x2, int y2) {
        gl.glPointSize(1.0f);
        gl.glBegin(GL.GL_POINTS);
    
        int samples = 100;
        float dx = (x2 - x1) / (float)samples;
        float dy = (y2 - y1) / (float)samples;
    
        for( int i = 0; i < samples; i++ )
        {
            gl.glVertex2f( i * dx, i * dy );
        } 
    
        gl.glEnd();//end drawing of points
    }
    

    Adjust samples to taste.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like the following code to work: double num = 31415; /* num will
I have the following exercise: Define a class named circle that accepts objects of
I'm currently learning about structs, so I have the following exercise: Set a Struct
I have the following exercise but am not sure on how I should begin.
i have the following code which will displays result in a UItable view along
I'm working on a college exercise and have the following question: What is the
What I would like to do is have the user add a new record
I have the following code, copied exactly from a exercise from a PHP book.
I have the following exercise: The parameter weekday is True if it is a
i have to crawl last.fm for users (university exercise). I'm new to python and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.