Skip to content

Instantly share code, notes, and snippets.

View beugnen's full-sized avatar

Beugnen beugnen

  • Australia
View GitHub Profile
#region Copyright
// Copyright 2014 Michael A. R. Duncan
// You are free to do whatever you want with this source
// File: Galaxy1Controller.cs
#endregion
#region
// Copyright 2014 Michael A. R. Duncan
// You are free to do whatever you want with this source
//
// File: Galaxy1Compute.compute
// Each #kernel tells which function to compile; you can have many kernels
#pragma kernel UpdateStars
#include "Galaxy.cginc"
void MyDualFramebufferView::RenderToMainscreen(IDrawable& drawable)
{
// switch back to main
glClearColor(1, 0, 0, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// trigger mipmaps generation explicitly
glBindTexture(GL_TEXTURE_2D, _fboTextureID);
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
@beugnen
beugnen / MyDualFramebufferView.cpp
Created May 20, 2012 01:14
Draw Secondary FBO
void MyDualFramebufferView::DrawToBackbuffer(IDrawable& drawable)
{
// use off screen FBO
glBindFramebuffer(GL_FRAMEBUFFER, _frameBufferID);
glViewport(0,0, cxFBO, cyFBO);
glClearColor(0, 0, 0, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@beugnen
beugnen / MyViewController.m
Created May 20, 2012 01:09
FBO Draw Sequence
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
_myView->DrawToBackbuffer(); // this will draw in 2nd FBO
[((GLKView *) self.view) bindDrawable]; // reset to main framebuffer
_myView->RenderToMainscreen();
}
@beugnen
beugnen / MyDualFramebufferView.cpp
Created May 20, 2012 00:22
Creating a Render to Texture Secondary Framebuffer for iOS OpenGL ES 2
GLsizei cxFBO;
GLsizei cyFBO;
GLuint _frameBufferID;
GLuint _colorRenderBuffer;
GLuint _depthRenderBuffer;
GLuint _fboTextureID;
void MyDualFramebufferView::Resize(GLfloat width, GLfloat height, GLfloat scale)
{
_scale = scale;
@beugnen
beugnen / MyViewController.m
Created May 20, 2012 00:16
iOS OpenGL ES 2 Creating Secondary Framebuffer
...MyDualFramebufferView _myView;
- (void)viewWillLayoutSubviews
{
CGRect rc = self.view.bounds;
GLfloat scale=1;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
{
scale = [[UIScreen mainScreen] scale] ;