Skip to content

Commit

Permalink
Include simple animation to demonstrate the render loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejSpanel authored and httpdigest committed Dec 6, 2019
1 parent 4d4c75d commit c8385e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions test/org/lwjgl/opengl/awt/AWTTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ public void paintGL() {
int w = getWidth();
int h = getHeight();
float aspect = (float) w / h;
double now = System.currentTimeMillis() * 0.001;
float width = (float) Math.abs(Math.sin(now * 0.3));
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, w, h);
glBegin(GL_QUADS);
glColor3f(0.4f, 0.6f, 0.8f);
glVertex2f(-0.75f / aspect, 0.0f);
glVertex2f(-0.75f * width / aspect, 0.0f);
glVertex2f(0, -0.75f);
glVertex2f(+0.75f / aspect, 0);
glVertex2f(+0.75f * width/ aspect, 0);
glVertex2f(0, +0.75f);
glEnd();
swapBuffers();
Expand Down
7 changes: 5 additions & 2 deletions test/org/lwjgl/opengl/awt/AWTThreadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void dispose() {
AWTGLCanvasExplicitDispose canvas;
frame.add(canvas = new AWTGLCanvasExplicitDispose(data) {
private static final long serialVersionUID = 1L;

public void initGL() {
System.out.println("OpenGL version: " + effective.majorVersion + "." + effective.minorVersion + " (Profile: " + effective.profile + ")");
createCapabilities();
Expand All @@ -58,13 +59,15 @@ public void paintGL() {
int w = getWidth();
int h = getHeight();
float aspect = (float) w / h;
double now = System.currentTimeMillis() * 0.001;
float width = (float) Math.abs(Math.sin(now * 0.3));
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, w, h);
glBegin(GL_QUADS);
glColor3f(0.4f, 0.6f, 0.8f);
glVertex2f(-0.75f / aspect, 0.0f);
glVertex2f(-0.75f * width / aspect, 0.0f);
glVertex2f(0, -0.75f);
glVertex2f(+0.75f / aspect, 0);
glVertex2f(+0.75f * width/ aspect, 0);
glVertex2f(0, +0.75f);
glEnd();
swapBuffers();
Expand Down

0 comments on commit c8385e8

Please sign in to comment.