Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GtkGL Renderer Module #195

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions base/include/Background.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void background_draw (void);
void background_init (void);
void background_set_window (int width, int height);
12 changes: 12 additions & 0 deletions base/include/GLUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Get number of elements in an array:
#define NELEM(array) (sizeof(array) / sizeof(*(array)))

// Loop over an array of given size:
#define FOREACH_NELEM(array, nelem, iter) \
for (__typeof__(*(array)) *iter = (array); \
iter < (array) + (nelem); \
iter++)

// Loop over an array of known size:
#define FOREACH(array, iter) \
FOREACH_NELEM(array, NELEM(array), iter)
37 changes: 37 additions & 0 deletions base/include/GtkGlRenderer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include "Module.h"
#include <gtk/gtk.h>// remove this
class GtkGlRendererProps : public ModuleProps
{
public:
GtkGlRendererProps(GtkWidget* _glArea, int _windowWidth, int _windowHeight) : ModuleProps() // take gtk string
{
// gladeFileName = _gladeFileName;
glArea = _glArea;
windowWidth = _windowWidth;
windowHeight = _windowHeight;
}
GtkWidget* glArea;
int windowWidth, windowHeight;
};

class GtkGlRenderer : public Module
{
public:
GtkGlRenderer(GtkGlRendererProps props);
~GtkGlRenderer();

bool init();
bool term();
// wait_for_exit

protected:
bool process(frame_container& frames);
bool processSOS(frame_sp &frame);
bool validateInputPins();
bool shouldTriggerSOS();
private:
class Detail;
boost::shared_ptr<Detail> mDetail;
};
4 changes: 4 additions & 0 deletions base/include/Matrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
void mat_frustum (float *matrix, float angle_of_view, float aspect_ratio, float z_near, float z_far);
void mat_translate (float *matrix, float dx, float dy, float dz);
void mat_rotate (float *matrix, float x, float y, float z, float angle);
void mat_multiply (float *matrix, float *a, float *b);
7 changes: 7 additions & 0 deletions base/include/Model.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void model_init (void);
void model_draw (void);
void draw_frames(void);
void drawCameraFrame(void* frameData, int width, int height);
const float *model_matrix(void);
void model_pan_start (int x, int y);
void model_pan_move (int x, int y);
22 changes: 22 additions & 0 deletions base/include/Program.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <GL/gl.h>

void initProgram (void);
void programs_init (void);
void program_cube_use (void);
void program_bkgd_use (void);

enum LocBkgd {
LOC_BKGD_VERTEX,
LOC_BKGD_TEXTURE,
};

enum LocCube {
LOC_CUBE_VIEW,
LOC_CUBE_MODEL,
LOC_CUBE_VERTEX,
LOC_CUBE_VCOLOR,
LOC_CUBE_NORMAL,
};

GLint program_bkgd_loc (const enum LocBkgd);
GLint program_cube_loc (const enum LocCube);
5 changes: 5 additions & 0 deletions base/include/View.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
void initZVal(void);
const float *view_matrix (void);
void view_set_window (int width, int height);
void view_z_decrease (void);
void view_z_increase (void);
147 changes: 147 additions & 0 deletions base/src/Background.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#include <gdk/gdk.h>
//yash change
// #include <GL/gl.h>
#ifndef GL_H
#define GL_H
#include <GL/glew.h>
#include <GL/glut.h>
#endif
// #include <GL/gl.h>
#include "Program.h"

static GLuint texture;
static GLuint vao, vbo;

// Each vertex has space and texture coordinates:
struct vertex {
float x;
float y;
float u;
float v;
} __attribute__((packed));

void
background_set_window (int width, int height)
{
float wd = (float)width / 16;
float ht = (float)height / 16;

// The background quad is made of four vertices:
//
// 3--2
// | |
// 0--1
//
struct vertex vertex[4] = {
{ -1, -1, 0, 0 }, // Bottom left
{ 1, -1, wd, 0 }, // Bottom right
{ 1, 1, wd, ht }, // Top right
{ -1, 1, 0, ht }, // Top left
};

GLint loc_vertex = program_bkgd_loc(LOC_BKGD_VERTEX);
GLint loc_texture = program_bkgd_loc(LOC_BKGD_TEXTURE);

glBindVertexArray(vao);

glEnableVertexAttribArray(loc_vertex);
glEnableVertexAttribArray(loc_texture);

glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex), vertex, GL_STATIC_DRAW);

glVertexAttribPointer(loc_vertex, 2, GL_FLOAT, GL_FALSE,
sizeof(struct vertex),
(void *) offsetof(struct vertex, x));

glVertexAttribPointer(loc_texture, 2, GL_FLOAT, GL_FALSE,
sizeof(struct vertex),
(void *) offsetof(struct vertex, u));

glBindVertexArray(0);
}

void
background_draw (void)
{
// Array of indices. We define two counterclockwise triangles:
// 0-2-3 and 2-0-1
//yash change
// static GLubyte index[6] = {
// 0, 1, 1,
// 2, 0, 1,
// 1, 3, 0
// };
static GLubyte triangle1[] = {
0, 1, 2,
0, 2, 3
};

static GLubyte triangle2[] = {
4, 5, 6,
4, 6, 7
};


program_bkgd_use();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glBindVertexArray(vao);
//yash change
// glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, index);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, triangle1);

// Draw the second triangle
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, triangle2);
//yash change end
glBindVertexArray(0);
}

void
background_init (void)
{
// Inline data declaration:
// extern char _binary_textures_background_png_start[];
// extern char _binary_textures_background_png_end[];

// char *start = _binary_textures_background_png_start;
// size_t len = _binary_textures_background_png_end
// - _binary_textures_background_png_start;

char *start ="start";
size_t len = strlen(start);

GInputStream *stream;
GdkPixbuf *pixbuf;

// Create an input stream from inline data:
stream = g_memory_input_stream_new_from_data(start, len, NULL);

// Generate a pixbuf from the input stream:
pixbuf = gdk_pixbuf_new_from_stream(stream, NULL, NULL);

// Destroy the stream:
g_object_unref(stream);

// Generate an OpenGL texture from pixbuf;
// hack a bit by not accounting for pixbuf rowstride:
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
gdk_pixbuf_get_width(pixbuf),
gdk_pixbuf_get_height(pixbuf), 0, GL_RGB, GL_UNSIGNED_BYTE,
gdk_pixbuf_get_pixels(pixbuf));

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

// Generate empty buffer:
glGenBuffers(1, &vbo);

// Generate empty vertex array object:
glGenVertexArrays(1, &vao);
}
Loading
Loading