Coder Social home page Coder Social logo

matogl's Introduction

Access OpenGL from MATLAB

Access the OpenGL rendering pipeline directly from matlab.

No mex file, toolbox, or any other external library needed.

View Matlab OpenGL on File Exchange

Examples

A few examples are included, see doc/GettingStarted.mlx for a brief description of some of them. You can open the files and see the inner workings.

3D Viewer Example

Screenshot 2021-12-07 153637 Screenshot 2021-12-07 153653

Fractal Viewer Example

Screenshot 2021-12-07 153529 image

Making your own application

The main starting point is the class GLController (or glmu.GLController to use the functions in the glmu package). Set it as a superclass for your class that manages the rendering.

You need to define the following abstract methods. In each of these methods, the gl argument is the current GL context.

  • InitFcn(obj,gl,varargin)

    • Called once when you run canvas.Init(arg1, arg2, ...) in your class initialization method.
    • This should contain your opengl initialization stuff.
  • UpdateFcn(obj,gl)

    • Called everytime canvas.Update() is called. It has some built in stuff to resize when needed and to skip updates that saturate the render process.
    • This should contain your opengl render pipeline for each frame update requested.
  • ResizeFcn(obj,gl,sz)

    • Called once after initialization, just before the first frame update, and when the user changes the window size.
    • Always called just before the UpdateFcn(...), when needed.
    • This should contain your opengl resize pipeline.
    • This one is optionnal. If not set, it defaults to gl.glViewport(0,0,sz(1),sz(2));

There are two ways to setup the render process.

All in one way

Make a GLController subclass like so:

classdef myApp < GLController
  methods
    function obj = myApp()
      frame = JFrame('myApp'); % create java frame
      canvas = GLCanvas('GL3'); % create glcanvas
      frame.add(canvas); % add glcanvas
      obj.setGLCanvas(canvas); % set obj as the canvas controller
      canvas.Init;
    end
    
    function InitFcn(obj,gl)
      %...
    end
    
    function UpdateFcn(obj,gl)
      %...
    end
  end
end

Separate controller way

If you don't want to end with a huge class, you can make a separate GLController just for the Init, Resize and Update functions. Make the GLController subclass:

classdef myController < GLController
  methods
    function InitFcn(obj,gl)
      %...
    end
    
    function UpdateFcn(obj,gl)
      %...
    end
  end
end

Then, in the main application, you can create the window with:

frame = JFrame('WindowName'); % create java frame
canvas = GLCanvas('GL3'); % create glcanvas
frame.add(canvas); % add glcanvas
ctrl = myController; % construct the controller
ctrl.setGLCanvas(canvas); % assign the canvas
canvas.Init;

Using gl when not in InitFcn, UpdateFcn or ResizeFcn

You can call gl commands when not inside one of these functions. To do so, use [gl,temp] = canvas.getContext. The temp output argument is the context lock and must be requested. When temp goes out of scope, gl commands will throw errors or run without doing anything.

GL Matlab Utility (glmu)

An utility package is included in gl\+glmu. To use this package, the controller must be a glmu.GLController. The more advanced examples use it.

It is not needed to make your own application. However, it helps a lot to abstract some opengl stuff. Feel free to make your own or to contribute to this project!

Addons using matogl

If you make and publish an addon using matogl, I would be happy to add it to this list.

matogl's People

Contributors

draingangscholar avatar fr0nkk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.