1. Trang chủ
  2. » Giáo Dục - Đào Tạo

OpenGL overview (đồ họa máy TÍNH SLIDE)

40 22 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 40
Dung lượng 603,65 KB

Nội dung

OpenGL Overview OpenGL and GLUT Overview • What is OpenGL & what can it for me? • OpenGL in windowing systems • Why GLUT • A GLUT program template What Is OpenGL? • Graphics rendering API – – • a cross-platform API high-quality color images composed of geometric and image primitives widely used in CAD, virtual reality, scientific visualization, information visualization and video game development OpenGL Architecture OpenGL as a Renderer • Geometric primitives – • points, lines and polygons Image Primitives – – images and bitmaps separate pipeline for images and geometry • • linked through texture mapping Rendering depends on state – colors, materials, light sources, etc Related APIs • • • AGL, GLX, WGL – glue between OpenGL and windowing systems GLU (OpenGL Utility Library) – – part of OpenGL NURBS, tessellators, quadric shapes, etc GLUT (OpenGL Utility Toolkit) – – – – portable windowing API keyboard and mouse input Geometric primitives: cubes, spheres, and teapot not officially part of OpenGL OpenGL and Related APIs application program OpenGL Motif GLUT widget or similar GLX, AGL or WGL X, Win32, Mac O/S software and/or hardware GLU GL What is JOGL? • Java OpenGL is a wrapper library by the Game Technology Group at Sun Microsystems that allow OpenGL to be used in Java • • • The base OpenGL C API is accessed in JOGL via Java Native Interface (JNI) calls The straightforward mapping of the OpenGL C API to Java methods Other Java OpenGL wrappers: GL4Java, JGL, LWJGL (Light-Weight Java Game Library) Setting Up JOGL 2.0x • Download the latest "stable" release from JogAMP http://jogamp.org/deployment/jogamp-current/archive Select "jogamp-all-platforms.7z" • Setup Library – – Copy the necessary jar-file, native libraries of your operating platform, and source-files into the appropriate sub-directories for Win32, copy • • • • "jar\gluegen-rt.jar", "jar\jogl.all.jar" into "jar"; all files in "lib\windows-i586" into "lib"; "gluegen-java-src.zip", "jogl-java-src.zip" into "src" Unzip the javadocs downloaded into "javadoc" Preliminaries • Headers Files // must import OpenGL im p ort javax.media.opengl.GL2; // import GL constants im p ort static javax.media.opengl.GL2.*; im p ort javax.media.opengl.glu.GLU; im p ort com.jogamp.opengl.util.gl2.GLUT im p ort javax.media.opengl.GLAutoDrawable; im p ort javax.media.opengl.GLCapabilities; im p ort javax.media.opengl.GLEventListener; im p ort javax.media.opengl.GLProfile; im p ort javax.media.opengl.awt.GLJPanel; Shapes Tutorial Controlling Rendering Appearance • From Wireframe to Texture Mapped OpenGL’s State Machine • All rendering attributes are encapsulated in the OpenGL State – – – – rendering styles shading lighting texture mapping Manipulating OpenGL State • Appearance is controlled by current state for each (primitive to render) { update OpenGL state render primitive } • Manipulating vertex attributes is most common way to manipulate state • • • glColor*() / glIndex*() glNormal*() glTexCoord*() Controlling current state • Setting State – – – • glPointSize(size); glLineStipple(repeat, pattern); glShadeModel(GL_SMOOTH); Enabling Features – – – glEnable(cap); glDisable(cap); cap is a feature like: • GL_LIGHTING, GL_TEXTURE_2D, GL_CULL_FACE, GL_BLEND, OpenGL State Variables • You can query the State Machine to determine the state of any variable • Any feature you enable or disable with glEnable / glDisable as well as numeric settings set with glSet can be queried with the many variations of glGet • Example byte color[3]; gl.glColor3ub(color[0], color[1], color[2]); gl.glColor3bv(color); fl o at colorf[3]; gl.glGetFloatv(GL_CURRENT_COLOR, colorf, 0); Animation and Depth Buffering Depth Buffering and Animation • Discuss double buffering and animation • Discuss hidden surface removal using the depth buffer Animation using Double Buffering 1 2 Front Buffer Back 16 16 Display Buffer Animation and Double Buffering • Request a double buffered color buffer – • Default for JOGL Clear color buffer – gl.glClear(GL_COLOR_BUFFER_BIT); • Render scene • Request swap of front and back buffers – • gl.glFlush(); Repeat steps - for animation Depth Buffering and Hidden Surface Removal 1 2 Color Buffer 16 Depth 16 Display Buffer Hidden Surface Removal Depth Buffering Using OpenGL • • • • • Request a depth buffer Enable depth buffering – glEnable(GL_DEPTH_TEST); Clear color and depth buffers – glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Render scene Swap color buffers An Updated Program Template • Depth Buffer phải xóa trước vẽ p u b lic void display(G LAutoD raw able draw able) { G L2 gl= draw able.getG L().getG L2(); // clear color and depth buff ers gl.glClear(G L_CO LO R_BU FFER_BIT | G L_D EPTH _BU FFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(0.0f,0.0f,-5.0f); } An Updated Program Template (cont) void init() { glClearColor(0.0, 0.0, 1.0, 1.0); } void drawScene() { fl o at vertices[] = { … }; fl o at colors[] = { … }; gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gl.glBegin(GL_TRIANGLE_STRIP); /* calls to glColor*() and glVertex*() */ gl.glEnd(); gl.glflush(); } .. .OpenGL and GLUT Overview • What is OpenGL & what can it for me? • OpenGL in windowing systems • Why GLUT • A GLUT program template What Is OpenGL? • Graphics rendering... // must import OpenGL im p ort javax.media .opengl. GL2; // import GL constants im p ort static javax.media .opengl. GL2.*; im p ort javax.media .opengl. glu.GLU; im p ort com.jogamp .opengl. util.gl2.GLUT... javax.media .opengl. GLAutoDrawable; im p ort javax.media .opengl. GLCapabilities; im p ort javax.media .opengl. GLEventListener; im p ort javax.media .opengl. GLProfile; im p ort javax.media .opengl. awt.GLJPanel;

Ngày đăng: 29/03/2021, 08:19

TỪ KHÓA LIÊN QUAN

w