CMSC427 OpenGL and JOGL

Similar documents
CMSC427 Fall 2017 OpenGL Notes A: Starting with JOGL and OpenGL Objectives of notes Readings Computer Graphics Programming in OpenGL with Java

OUTLINE. Learn the basic design of a graphics system Introduce pipeline architecture Examine software components for a graphics system

OPENGL AND GLSL. Computer Graphics

Programming of Graphics

INSTANCE VARIABLES (1/2) P. 1

An Introduction to 2D OpenGL

Shaders. Slide credit to Prof. Zwicker

INTRODUCTION. Computer Graphics

COMP3421 Computer Graphics

Lecture 5 Vertex and Fragment Shaders-1. CITS3003 Graphics & Animation

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

OUTLINE. Implementing Texturing What Can Go Wrong and How to Fix It Mipmapping Filtering Perspective Correction

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

WebGL and GLSL Basics. CS559 Fall 2015 Lecture 10 October 6, 2015

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Mobile Application Programing: Android. OpenGL Operation

Shader Programming. Daniel Wesslén, Stefan Seipel, Examples

The Graphics Pipeline

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

The Graphics Pipeline

Lecture 9(B): GPUs & GPGPU

CS 380 Introduction to Computer Graphics. LAB (1) : OpenGL Tutorial Reference : Foundations of 3D Computer Graphics, Steven J.

CSE 167: Introduction to Computer Graphics Lecture #13: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

CS4621/5621 Fall Computer Graphics Practicum Intro to OpenGL/GLSL

Mobile Application Programing: Android. OpenGL Operation

SHADER PROGRAMMING. Based on Jian Huang s lecture on Shader Programming

JOGL 3D GRAPHICS. Drawing a 3D line. In this chapter, let us see how to deal with 3D graphics.

Ciril Bohak. - INTRODUCTION TO WEBGL

Copyright Khronos Group 2012 Page 1. Teaching GL. Dave Shreiner Director, Graphics and GPU Computing, ARM 1 December 2012

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

OPENGL RENDERING PIPELINE

Introductory Seminar

CS475/CS675 - Computer Graphics. OpenGL Drawing

COMP371 COMPUTER GRAPHICS

CS 432 Interactive Computer Graphics

Shader Programming 1. Examples. Vertex displacement mapping. Daniel Wesslén 1. Post-processing, animated procedural textures

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

Adding New Features to the CS 5625 Framework. Pramook Khungurn

Mobile graphics API Overview

Shadows. Prof. George Wolberg Dept. of Computer Science City College of New York

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

Introduction to Shaders.

The Projection Matrix

Advanced Graphics. OpenGL and Shaders I. Alex Benton, University of Cambridge Supported in part by Google UK, Ltd

COMP3421/9415 Computer Graphics

Mobile Application Programming: Android. OpenGL Operation

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

last time put back pipeline figure today will be very codey OpenGL API library of routines to control graphics calls to compile and load shaders

WebGL (Web Graphics Library) is the new standard for 3D graphics on the Web, designed for rendering 2D graphics and interactive 3D graphics.

Supplement to Lecture 22

CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

The Projection Matrix

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Sign up for crits! Announcments

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

Converts geometric primitives into images Is split into several independent stages Those are usually executed concurrently

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

Best practices for effective OpenGL programming. Dan Omachi OpenGL Development Engineer

Programmable GPUs. Real Time Graphics 11/13/2013. Nalu 2004 (NVIDIA Corporation) GeForce 6. Virtua Fighter 1995 (SEGA Corporation) NV1

EDAF80 Introduction to Computer Graphics. Seminar 3. Shaders. Michael Doggett. Slides by Carl Johan Gribel,

Programmable Graphics Hardware

2D graphics with WebGL

Programming shaders & GPUs Christian Miller CS Fall 2011

Blis: Better Language for Image Stuff Project Proposal Programming Languages and Translators, Spring 2017

Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

CPSC 436D Video Game Programming

WebGL: Hands On. DevCon5 NYC Kenneth Russell Software Engineer, Google, Inc. Chair, WebGL Working Group

Mali & OpenGL ES 3.0. Dave Shreiner Jon Kirkham ARM. Game Developers Conference 27 March 2013

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects

Rasterization Overview

Introduction to Computer Graphics. Hardware Acceleration Review

Geovisualisation Of Animated Tides In Coastal Area

GLSL Overview: Creating a Program

Dave Shreiner, ARM March 2009

CSE 4431/ M Advanced Topics in 3D Computer Graphics. TA: Margarita Vinnikov

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

The Graphics Pipeline

Real-Time 2D to 2D+Depth Video Conversion. OzViz David McKinnon QUT

LSU EE Homework 5 Solution Due: 27 November 2017

12.2 Programmable Graphics Hardware

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

Animation Essentially a question of flipping between many still images, fast enough

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

CS452/552; EE465/505. Image Processing Frame Buffer Objects

Programmable shader. Hanyang University

Today s Agenda. Shaders fundamentals. Programming with shader-based OpenGL

CS559 Computer Graphics Fall 2015

OUTLINE. Tessellation in OpenGL Tessellation of Bezier Surfaces Tessellation for Terrain/Height Maps Level of Detail

Starting out with OpenGL ES 3.0. Jon Kirkham, Senior Software Engineer, ARM

Understanding M3G 2.0 and its Effect on Producing Exceptional 3D Java-Based Graphics. Sean Ellis Consultant Graphics Engineer ARM, Maidenhead

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

HW-Tessellation Basics

Advanced Graphics. OpenGL and Shaders I. Alex Benton, University of Cambridge Supported in part by Google UK, Ltd

3d Programming I. Dr Anton Gerdelan

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

Models and Architectures

CSE 167: Lecture #8: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Transcription:

CMSC427 OpenGL and JOGL

Step 1: Configuring and compiling In Eclipse following previous instructions Get from web page CMSC427OpenGLCode.zip Add graphics3dlib.jar to JOGL project From command line Add jar files to CLASSPATH Use.bat file cmds javac code/code.java Java code.code If on Mac, follow errata

Step 2: Creating a GLCanvas (Gordon 2.1) public class Code extends JFrameimplements GLEventListener { private GLCanvasmyCanvas; public Code() { settitle("chapter2 - program1"); setsize(600,400); setlocation(200,200); // Added for Mac GLProfile glp = GLProfile.getMaxProgrammableCore(true); GLCapabilities caps = new GLCapabilities(glp); mycanvas = new GLCanvas(caps); // Replacing this line //mycanvas = new GLCanvas(); mycanvas.addgleventlistener(this); getcontentpane().add(mycanvas); setvisible(true);

Step 2: Creating a GLCanvas (Gordon 2.1) public void display(glautodrawabledrawable) { GL4 gl = (GL4) GLContext.getCurrentGL(); float bkg[] = { 1.0f, 1.0f, 0.0f, 1.0f ; FloatBuffer bkgbuffer = Buffers.newDirectFloatBuffer(bkg); gl.glclearbufferfv(gl_color, 0, bkgbuffer); System.out.println("display"); If not OpenGL version 4, change to GL3 or GL2 Println helps track display events

Programmable pipeline and shaders Functionality in parts (grey boxes) of the GPU pipeline specified by user programs Called shaders, or shader programs, executed on GPU Not all functionality in the pipeline is programmable GPU Scene data Vertex processing, modeling and viewing transformation Projection Rasterization, fragment processing, visibility Image 5

Step 3: Compiling shaders Shader programs are compiled and linked in Java program, sent to GPU Appear as strings in Java program String vshadersource[] = { "#version 410 \n", "void main(void) \n", "{ gl_position = vec4(0.0, 0.0, 0.0, 1.0); \n" ; String fshadersource[] = { "#version 410 \n", "out vec4 color; \n", "void main(void) \n", "{ color = vec4(0.0, 0.0, 1.0, 1.0); \n" ;

Step 3: Compiling shaders // This code can be copied verbatim between programs only write once int vshader = gl.glcreateshader(gl_vertex_shader); int fshader = gl.glcreateshader(gl_fragment_shader); gl.glshadersource(vshader, vshadersource.length, vshadersource, null, 0); gl.glcompileshader(vshader); gl.glshadersource(fshader, fshadersource.length, fshadersource, null, 0); gl.glcompileshader(fshader); int vfprogram = gl.glcreateprogram(); gl.glattachshader(vfprogram, vshader); gl.glattachshader(vfprogram, fshader); gl.gllinkprogram(vfprogram); gl.gldeleteshader(vshader); gl.gldeleteshader(fshader); return vfprogram;

Step 4: Reading shaders Vert.shader: This shader sets a fixed location for every vertex. #version 410 void main(void) { gl_position = vec4(0.0, 0.0, 0.5, 1.0); Frag.shader: This shader sets a fixed color for every pixel. #version 410 out vec4 color; void main(void) { color = vec4(0.0, 0.0, 1.0, 1.0);

Step 5: Reading shaders, second example Three positions for three vertices => triangle #version 410 void main(void) { if (gl_vertexid == 0) gl_position = vec4( 0.25,-0.25, 0.0, 1.0); else if (gl_vertexid == 1) gl_position = vec4(-0.25,-0.25, 0.0, 1.0); else gl_position = vec4( 0.25, 0.25, 0.0, 1.0);

Step 6: Animation Animator object in Java: FPSAnimator animator = new FPSAnimator(myCanvas, 30); animator.start(); Animation in shader:. #version 410 uniform float inc; void main(void) { if (gl_vertexid == 0) gl_position = vec4( 0.25+inc,-0.25, 0.0, 1.0); else if (gl_vertexid == 1) gl_position = vec4(-0.25+inc,-0.25, 0.0, 1.0); else gl_position = vec4( 0.25+inc, 0.25, 0.0, 1.0);

Step 6: Animation Animator object in Java: FPSAnimator animator = new FPSAnimator(myCanvas, 30); animator.start(); Animation in shader:. #version 410 uniform float inc; void main(void) { if (gl_vertexid == 0) gl_position = vec4( 0.25+inc,-0.25, 0.0, 1.0); else if (gl_vertexid == 1) gl_position = vec4(-0.25+inc,-0.25, 0.0, 1.0); else gl_position = vec4( 0.25+inc, 0.25, 0.0, 1.0);

Step 6: Animation The value of x is passed into the Shader through the glprogramuniform1f call. The glgetuniformlocation() call gets a ptr to the shader variable (and, yes, we re passing x here to inc in the shader, so a variable name confusion). x += inc; int offset_loc = gl.glgetuniformlocation(rendering_program, "inc"); gl.glprogramuniform1f(rendering_program, offset_loc, x);

Step 7: Passing in vertices Finally, if we want to pass vertices into the Shader we need to pass VBOs Vertex Buffer Objects that contain vertex information such as Position Normal Color Texture coordinates