Code Monkey home page Code Monkey logo

arduinogl's Introduction

ArduinoGL : OpenGL for Arduino

This is a very small subset of OpenGL 1.0 written for Arduino UNO (although it should run on other more powerful Arduinos as well). This library also includes code to draw the frame buffer on a PCD8544 LCD display (Nokia 5110 display).

This is just a proof of concept, it is not meant to run fast or suit any application.

Features

It is able to draw 2D and 3D wireframes! It has no backface culling, no frustum culling, no colours, no depth/z buffer, no textures, no lighting, no shading, etc...

glBegin(mode) only supports GL_POINTS, GL_POLYGON and GL_TRIANGLE_STRIP. Since Arduino UNO has only 2 Kb of RAM, there is a limit to the number of matrices on the stack (#define MAX_MATRICES 8) and vertices being processed (#define MAX_VERTICES 24) .

Hookup

Follow this sparkfun guide to hookup your PCD8544 display. Before running any example, check if your wiring is correct!

Installation

Create an ArduinoGL directory inside your ~/Arduino/libraries/ directory, then copy all the contents of this repository to that new directory. After that you will be able to compile and run all the examples on the Arduino IDE.

Example

This example reads an angle from analog pin A0, uses a camera with a perspective projection (gluPerspective(...)), and draws a rotated and scaled cube.

Code

#include <ArduinoGL.h>
#include <Canvas.h>
#include <PCD8544.h>

PDC8544 display(7, 6, 5, 11, 13, 9);
Canvas c;

void drawCube() {                

  glBegin(GL_POLYGON);
    glVertex3f(-1, -1, -1);
    glVertex3f(1, -1, -1);
    glVertex3f(1, 1, -1);
    glVertex3f(-1, 1, -1);
  glEnd();

  glBegin(GL_POLYGON);
    glVertex3f(1, -1, -1);
    glVertex3f(1, -1, 1);
    glVertex3f(1, 1, 1);
    glVertex3f(1, 1, -1);
  glEnd();

  glBegin(GL_POLYGON);
    glVertex3f(1, -1, 1);
    glVertex3f(-1, -1, 1);
    glVertex3f(-1, 1, 1);
    glVertex3f(1, 1, 1);
  glEnd();

  glBegin(GL_POLYGON);
    glVertex3f(-1, -1, 1);
    glVertex3f(-1, -1, -1);
    glVertex3f(-1, 1, -1);
    glVertex3f(-1, 1, 1);
  glEnd();

  glBegin(GL_POLYGON);
    glVertex3f(-1, -1, 1);
    glVertex3f(1, -1, 1);
    glVertex3f(1, -1, -1);
    glVertex3f(-1, -1, -1);
  glEnd();

  glBegin(GL_POLYGON);
    glVertex3f(-1, 1, -1);
    glVertex3f(1, 1, -1);
    glVertex3f(1, 1, 1);
    glVertex3f(-1, 1, 1);
  glEnd();
}

void setup() {

  display.begin();
  display.clear();
  
  glUseCanvas(&c);
  glClear(GL_COLOR_BUFFER_BIT);
    
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(30.0, c.width()/c.height(), 0.1f, 9999.f);
    
  glMatrixMode(GL_MODELVIEW);
}

void loop() {
  
  float angle = analogRead(0)/1024.f * 360.f;
  glClear(GL_COLOR_BUFFER_BIT); 
  
  glLoadIdentity();
  gluLookAt(10, 8, -10, 0, 0, 0, 0, 1, 0);
    
  glRotatef(angle, 0.f, 1.f, 0.f);
  glScalef(2.5f, 2.5f, 2.5f);
  
  drawCube();
  
  display.printBitmap(c.bitmap());
  delay(1);
}

Result

3D Models

You can use the STL_converter tool to convert any small STL model into a format that can be used with ArduinoGL.

Stanford Bunny

Developer

Fabio de Albuquerque Dela Antonio

arduinogl's People

Contributors

fabio914 avatar

Watchers

 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.