/** * レンダリング環境のセットアップ * * @param gcon */ public void begin(GraphicContext gcon) { GraphicContextJogl gc = (GraphicContextJogl) gcon; GL gl = gc.getGL(); if ((state_ & CLEAR) == CLEAR) { gl.glClearColor(r_, g_, b_, 1.0f); // カラープレーン初期値 gl.glClearDepth(1.0); // デプスバッファの初期値 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); } gl.glEnable(GL.GL_DEPTH_TEST); // デプスバッファをイネーブル gl.glDepthFunc(GL.GL_LESS); // デプスバッファの計算法指定 gl.glDepthMask(true); // デプスバッファをリードライト gl.glEnable(GL.GL_LIGHTING); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); float right = (float) (near_ * Math.tan(fovx_ / 2)); float left = -right; float top = right * aspect_; float bottom = -top; gl.glFrustum(left, right, bottom, top, near_, far_); buildViewMatrix(); gc.setViewMatrix(viewMatrix_); }
public void init(GLAutoDrawable drawable) { GL gl = drawable.getGL(); System.err.println("INIT GL IS: " + gl.getClass().getName()); gl.setSwapInterval(1); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glShadeModel(GL.GL_SMOOTH); // try setting this to GL_FLAT and see what happens. }
/** * Main drawing function. Inside this function the main part of the drawing is done. * * @param drawable the drawable object that is used to trigger the drawing actions */ @Override public void display(final GLAutoDrawable drawable) { final GL gl = drawable.getGL(); gl.glClearColor(0.f, 0.f, 0.f, 1.f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); manager.draw(); }
public void init(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadMatrixd(this._nyar.getGlProjectionMatrix(), 0); gl.glEnable(GL.GL_DEPTH_TEST); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); Animator animator = new Animator(drawable); animator.start(); return; }
/** * Set the color by index. * * @param index given index. */ public void setColor(int index) { int i = index; float b = (i % blueSize) / (blueSize - 1f); i = i >> blueSize; float g = (i % greenSize) / (greenSize - 1f); i = i >> greenSize; float r = (i % redSize) / (redSize - 1f); // gl.glColor3f(r, g, b); gl.glClearColor(r, g, b, 0); }
public void init(GLAutoDrawable gLDrawable) { renderer = new TextRenderer(new Font("SansSerif", Font.BOLD, 36)); // creates textrenderer GL gl = gLDrawable.getGL(); gl.glShadeModel(GL.GL_SMOOTH); // Enable Smooth Shading gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Black Background gl.glClearDepth(1.0f); // Depth Buffer Setup gl.glEnable(GL.GL_DEPTH_TEST); // Enables Depth Testing gl.glDepthFunc(GL.GL_LEQUAL); // The Type Of Depth Testing To Do // Really Nice Perspective Calculations gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); }
public void clearColorBuffer(int color) { float r, g, b, a; int ir, ig, ib, ia; ia = (color >> 24) & 0xff; ir = (color >> 16) & 0xff; ig = (color >> 8) & 0xff; ib = color & 0xff; a = ia / 255.0f; r = ir / 255.0f; g = ig / 255.0f; b = ib / 255.0f; gl.glClearColor(r, g, b, a); gl.glClear(GL.GL_COLOR_BUFFER_BIT); }
public void init(GL gl) { // Starts with animation turned off setAnimation(false); // --- OpenGL Initialization // Set background color to sky blue gl.glClearColor(0.58f, 0.74f, 0.98f, 0.0f); // Turn on Z buffer gl.glEnable(GL.GL_DEPTH_TEST); // Turn on Gouraud shaded polygons gl.glShadeModel(GL.GL_SMOOTH); // Turn on automatic normalization for normal vectors gl.glEnable(GL.GL_NORMALIZE); }
/** OpenGL initialization function Called once, on startup */ @Override public void init(GLAutoDrawable auto_drawable) { // initialize OpenGL state, load arrays, etc. // anything needs to be dont before the drawing calls final GL gl = auto_drawable.getGL(); gl.glShadeModel(GL.GL_SMOOTH); gl.glClearColor(1.0f, 0.0f, 0.0f, 0.0f); gl.glClearDepth(1.0f); gl.glEnable(GL.GL_DEPTH_TEST); gl.glDepthFunc(GL.GL_LEQUAL); gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY); gl.glEnableClientState(GL.GL_VERTEX_ARRAY); // set the texture mode to decal, so textures are rendered independent of // underlying colors gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_DECAL); // initialize vertex arrays initVertexArrays(); // enable 2D texturing gl.glEnable(GL.GL_TEXTURE_2D); // load the question texture question_Texture = loadTexture("Data/Pictures/question_mark.png"); // set up fog effect float fogColor[] = {0.5f, 0.5f, 0.5f, 1.0f}; // Fog Color gl.glFogi(GL.GL_FOG_MODE, GL.GL_LINEAR); // Fog Mode gl.glFogfv(GL.GL_FOG_COLOR, FloatArrayToFloatBuffer(fogColor)); // Set Fog Color gl.glFogf(GL.GL_FOG_DENSITY, 0.35f); // How Dense Will The Fog Be gl.glHint(GL.GL_FOG_HINT, GL.GL_NICEST); // Fog Hint Value gl.glFogf(GL.GL_FOG_START, 0.0f); // Fog Start Depth gl.glFogf(GL.GL_FOG_END, 3.0f); // Fog End Depth gl.glEnable(GL.GL_FOG); // Enables GL_FOG // load all textures LoadAllGuessModelTextures(guess_model_array); }
public void init(GLAutoDrawable drawable) { GL gl = drawable.getGL(); float m[] = { 0.0f, 1.0f, 0.0f, 0.0f, // 0.0f, 0.0f, 1.0f, 0.0f, // 1.0f, 0.0f, 0.0f, 0.0f, // 0.0f, 0.0f, 0.0f, 1.0f }; pixels = readImage("Data/leeds.bin", dim); System.out.println(pixels.toString()); gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glMatrixMode(GL.GL_COLOR); gl.glLoadMatrixf(m, 0); gl.glMatrixMode(GL.GL_MODELVIEW); }
private void initOpenGL() { pgl = (PGraphicsOpenGL) g; gl = pgl.gl; gl.setSwapInterval(1); gl.glShadeModel(GL.GL_SMOOTH); // Enable Smooth Shading gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background gl.glClearDepth(1.0f); // Depth Buffer Setup gl.glEnable(GL.GL_DEPTH_TEST); // Enables Depth Testing gl.glDepthFunc(GL.GL_LEQUAL); // The Type Of Depth Testing To Do gl.glHint( GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); // Really Nice Perspective Calculations gl.glDisable(GL.GL_TEXTURE_2D); // Set up lighting gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, lightAmbient, 0); gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, lightDiffuse, 0); // gl.glLightfv( GL.GL_LIGHT1, GL.GL_SPECULAR, lightSpecular, 0 ); gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, lightPosition, 0); gl.glEnable(GL.GL_LIGHTING); gl.glEnable(GL.GL_LIGHT1); }
public void clearTex(int glid, int target, int color) { float r, g, b, a; int ir, ig, ib, ia; ia = (color >> 24) & 0xff; ir = (color >> 16) & 0xff; ig = (color >> 8) & 0xff; ib = color & 0xff; a = ia / 255.0f; r = ir / 255.0f; g = ig / 255.0f; b = ib / 255.0f; pushFramebuffer(); setFramebuffer(FBO); FBO.setDrawBuffer(target, glid); gl.glClearColor(r, g, b, a); gl.glClear(GL.GL_COLOR_BUFFER_BIT); popFramebuffer(); }
public void init() { /* * Set the values used when clearing the screen */ gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); gl.glClearDepth(1); // gl.glEnable(GL.GL_DEPTH_TEST); // gl.glDepthFunc(GL.GL_LEQUAL); // gl.glDepthMask(true); glu = new GLU(); enableAlpha(); // gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); scaleX = 1; scaleY = 1; brushPos = new Vector(); currentTexture = null; textureCoords = null; }
void redraw(GL gl) { GOut g = new GOut(gl, getContext(), MainFrame.getInnerSize()); synchronized (ui) { ui.update(); } if (Config.render_enable) { gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0, getWidth(), 0, getHeight(), -1, 1); TexRT.renderall(g); if (curf != null) curf.tick("texrt"); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0, getWidth(), getHeight(), 0, -1, 1); gl.glClearColor(0, 0, 0, 1); gl.glClear(GL.GL_COLOR_BUFFER_BIT); if (curf != null) curf.tick("cls"); synchronized (ui) { ui.draw(g); } if (curf != null) curf.tick("draw"); if (Config.dbtext) { g.atext("FPS: " + fps, new Coord(10, 545), 0, 1); g.atext("Texhit: " + dth, new Coord(10, 530), 0, 1); g.atext("Texmiss: " + dtm, new Coord(10, 515), 0, 1); Runtime rt = Runtime.getRuntime(); long free = rt.freeMemory(), total = rt.totalMemory(); g.atext( String.format( "Mem: %,011d/%,011d/%,011d/%,011d", free, total - free, total, rt.maxMemory()), new Coord(10, 500), 0, 1); g.atext( String.format("LCache: %d/%d", Layered.cache.size(), Layered.cache.cached()), new Coord(10, 485), 0, 1); g.atext( String.format("RT-current: %d", TexRT.current.get(gl).size()), new Coord(10, 470), 0, 1); if (Resource.qdepth() > 0) g.atext( String.format("RQ depth: %d (%d)", Resource.qdepth(), Resource.numloaded()), new Coord(10, 455), 0, 1); } Object tooltip = ui.root.tooltip(mousepos, true); Tex tt = null; if (tooltip != null) { if (tooltip instanceof Text) { tt = ((Text) tooltip).tex(); } else if (tooltip instanceof Tex) { tt = (Tex) tooltip; } else if (tooltip instanceof String) { if (((String) tooltip).length() > 0) tt = (Text.render((String) tooltip)).tex(); } } if (tt != null) { Coord sz = tt.sz(); Coord pos = mousepos.add(sz.inv()); if (pos.x < 0) pos.x = 0; if (pos.y < 0) pos.y = 0; g.chcolor(244, 247, 21, 192); g.rect(pos.add(-3, -3), sz.add(6, 6)); g.chcolor(35, 35, 35, 192); g.frect(pos.add(-2, -2), sz.add(4, 4)); g.chcolor(); g.image(tt, pos); } } Resource curs = ui.root.getcurs(mousepos); if (!curs.loading) { if (cursmode == "awt") { if (curs != lastcursor) { try { setCursor(makeawtcurs(curs.layer(Resource.imgc).img, curs.layer(Resource.negc).cc)); ark.bot.cursor_name = curs.name; ark.bot.cursor_name = ark.bot.cursor_name.replace("gfx/hud/curs/", ""); lastcursor = curs; } catch (Exception e) { cursmode = "tex"; } } } else if (cursmode == "tex") { Coord dc = mousepos.add(curs.layer(Resource.negc).cc.inv()); g.image(curs.layer(Resource.imgc), dc); } } }
public void createPartControl(final Composite parent) { Composite top = new Composite(parent, SWT.NONE); top.setLayout(new FillLayout()); GLData data = new GLData(); data.doubleBuffer = true; canvas = new GLCanvas(top, SWT.NONE, data); canvas.setCurrent(); final GLContext context = GLDrawableFactory.getFactory().createExternalGLContext(); context.makeCurrent(); GL gl = context.getGL(); geocontext.initialize(context); gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); context.release(); canvas.addListener( SWT.Resize, new Listener() { public void handleEvent(Event event) { Rectangle bounds = canvas.getBounds(); canvas.setCurrent(); context.makeCurrent(); GL gl = context.getGL(); geocontext.setHeight(bounds.height); geocontext.setWidth(bounds.width); gl.glViewport(0, 0, bounds.width, bounds.height); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); new GLU().gluOrtho2D(0, 1, 0, 1); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); context.release(); } }); canvas.addMouseMoveListener( new MouseMoveListener() { @Override public void mouseMove(MouseEvent e) { if (e.stateMask == SWT.SHIFT) { dxx = (int) (geocontext.getZoom() * (e.x - canvas.getBounds().width / 2) / 10); dyy = (int) (geocontext.getZoom() * (e.y - canvas.getBounds().height / 2) / 10); geocontext.setDirty(true); } else { Point p = new Point(); try { p.x = (int) (geocontext.getX() + e.x * geocontext.getWidth() / canvas.getBounds().width * geocontext.getZoom()); p.y = (int) (geocontext.getY() + e.y * geocontext.getHeight() / canvas.getBounds().height * geocontext.getZoom()); root.mouseMoved(p, geocontext); } catch (Exception ex) { } } } }); canvas.addMouseWheelListener( new MouseWheelListener() { @Override public void mouseScrolled(MouseEvent e) { float zoom = (float) (geocontext.getZoom() * Math.pow(2, -e.count / 20.0)); // check mouse position int posX = e.x; int posY = e.y; // calculate the image position of the current position of the mouse int x = (int) (geocontext.getX() + posX * geocontext.getWidth() / canvas.getBounds().width * geocontext.getZoom()); int y = (int) (geocontext.getY() + posY * geocontext.getHeight() / canvas.getBounds().height * geocontext.getZoom()); geocontext.setZoom(zoom); // translate the image origin to have the same mouse position in the geocontext geocontext.setX( (int) (x - posX * geocontext.getWidth() / canvas.getBounds().width * geocontext.getZoom())); geocontext.setY( (int) (y - posY * geocontext.getHeight() / canvas.getBounds().height * geocontext.getZoom())); geocontext.setDirty(true); } }); final Runnable core = new Runnable() { int count = 0; long[] times = new long[500]; public void run() { if (!canvas.isDisposed()) { if (count == times.length) { count = 0; double fps = 0; for (int i = 0; i < times.length - 1; i++) { fps += (times[i + 1] - times[i]) / 1000.; } fps /= times.length - 1; System.out.println(1 / fps); } else { times[count++] = System.currentTimeMillis(); } canvas.setCurrent(); context.makeCurrent(); GL gl = context.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); if (dxx != 0 || dyy != 0) { dxx /= 1.2; dyy /= 1.2; geocontext.setX(geocontext.getX() + dxx); geocontext.setY(geocontext.getY() + dyy); } geocontext.initialize(context); geocontext.setDirty(true); root.render(geocontext); canvas.swapBuffers(); context.release(); try { Thread.sleep(15); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } canvas.getDisplay().asyncExec(this); } } }; canvas.getDisplay().asyncExec(core); registerView(); renderLayers(); }
public void setBackgroundColor(ColorRGBA color) { GL gl = GLContext.getCurrentGL(); gl.glClearColor(color.r, color.g, color.b, color.a); }
// display callback function public void display(final GLAutoDrawable drawable) { final GL gl = drawable.getGL(); // The usual OpenGL stuff to clear the screen and set up viewing. gl.glClearColor(.25f, .25f, .25f, 1.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(30.0f, 1.0f, .1f, 100); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt(4, 4, -4, 0, 0, 0, 0, 1, 0); // Make the object rotate a bit each time the display function // is called gl.glRotatef(curTime, 0, 1, 0); // Now make sure that the vertex and fragment programs, loaded // in LoadCgPrograms() are bound. CgGL.cgGLBindProgram(vertexProgram); CgGL.cgGLBindProgram(fragmentProgram); // Bind uniform parameters to vertex shader CgGL.cgGLSetStateMatrixParameter( CgGL.cgGetNamedParameter(vertexProgram, "ModelViewProj"), CgGL.CG_GL_MODELVIEW_PROJECTION_MATRIX, CgGL.CG_GL_MATRIX_IDENTITY); CgGL.cgGLSetStateMatrixParameter( CgGL.cgGetNamedParameter(vertexProgram, "ModelView"), CgGL.CG_GL_MODELVIEW_MATRIX, CgGL.CG_GL_MATRIX_IDENTITY); CgGL.cgGLSetStateMatrixParameter( CgGL.cgGetNamedParameter(vertexProgram, "ModelViewIT"), CgGL.CG_GL_MODELVIEW_MATRIX, CgGL.CG_GL_MATRIX_INVERSE_TRANSPOSE); // We can also go ahead and bind varying parameters to vertex shader // that we just want to have the same value for all vertices. The // vertex shader could be modified so that these were uniform for // better efficiency, but this gives us flexibility for the future. final float Kd[] = {.7f, .2f, .2f}, Ks[] = {.9f, .9f, .9f}; CgGL.cgGLSetParameter3fv(CgGL.cgGetNamedParameter(vertexProgram, "diffuse"), Kd, 0); CgGL.cgGLSetParameter3fv(CgGL.cgGetNamedParameter(vertexProgram, "specular"), Ks, 0); // Now bind uniform parameters to fragment shader final float lightPos[] = {3, 2, -3}; CgGL.cgGLSetParameter3fv(CgGL.cgGetNamedParameter(fragmentProgram, "Plight"), lightPos, 0); final float lightColor[] = {1, 1, 1}; CgGL.cgGLSetParameter3fv( CgGL.cgGetNamedParameter(fragmentProgram, "lightColor"), lightColor, 0); CgGL.cgGLSetParameter1f(CgGL.cgGetNamedParameter(fragmentProgram, "shininess"), 40); // And finally, enable the approprate texture for fragment shader; the // texture was originally set up in LoadTextures(). CgGL.cgGLEnableTextureParameter(CgGL.cgGetNamedParameter(fragmentProgram, "diffuseMap")); // And go ahead and draw the scene geometry DrawGeometry(gl); // Disable the texture now that we're done with it. CgGL.cgGLDisableTextureParameter(CgGL.cgGetNamedParameter(fragmentProgram, "diffuseMap")); ++curTime; }