Browse files

renamed: khronos/GLES2Man.lua -> GLES2Man.lua

	renamed:    khronos/GLESMan.lua -> GLESMan.lua
	renamed:    khronos/OpenVG.lua -> OpenVG.lua
	renamed:    khronos/OpenVG_Utils.lua -> OpenVG_Utils.lua
	modified:   cube_texture_and_coords.lua
	renamed:    khronos/egl.lua -> egl.lua
	renamed:    khronos/egl_utils.lua -> egl_utils.lua
	renamed:    khronos/eglplatform.lua -> eglplatform.lua
	renamed:    khronos/gl.lua -> gl.lua
	renamed:    khronos/gl2.lua -> gl2.lua
	renamed:    khronos/gl2ext.lua -> gl2ext.lua
	renamed:    khronos/glext.h -> glext.h
	renamed:    vcinclude/common.lua -> interface/common.lua
	renamed:    interface/vmcs_host/vc_cec.lua -> interface/vc_cec.lua
	renamed:    interface/vmcs_host/vc_cecservice.lua -> interface/vc_cecservice.lua
	renamed:    interface/vmcs_host/vc_dispmanx.lua -> interface/vc_dispmanx.lua
	renamed:    interface/vmcs_host/vc_dispmanx_types.lua -> interface/vc_dispmanx_types.lua
	renamed:    interface/vmcs_host/vc_dispservice_x_defs.lua -> interface/vc_dispservice_x_defs.lua
	renamed:    interface/vmcs_host/vc_hdmi.lua -> interface/vc_hdmi.lua
	renamed:    interface/vmcs_host/vc_hdmi_property.lua -> interface/vc_hdmi_property.lua
	renamed:    interface/vmcs_host/vc_tvservice.lua -> interface/vc_tvservice.lua
	renamed:    interface/vmcs_host/vc_tvservice_defs.lua -> interface/vc_tvservice_defs.lua
	renamed:    interface/vmcs_host/vcgencmd.lua -> interface/vcgencmd.lua
	modified:   interface/vctypes/vc_image_types.lua
	renamed:    khronos/khrplatform.lua -> khrplatform.lua
	modified:   rpiui.lua
	new file:   test_egles_basic.lua
	modified:   test_triangle.lua
	renamed:    khronos/vgext.lua -> vgext.lua
	renamed:    khronos/vgu.lua -> vgu.lua
  • Loading branch information...
1 parent 06bafcf commit eed00a13dce4f8ee79cbc70c9b0d107571e06bb2 @Wiladams committed Oct 14, 2012
View
0 khronos/GLES2Man.lua → GLES2Man.lua
File renamed without changes.
View
0 khronos/GLESMan.lua → GLESMan.lua
File renamed without changes.
View
0 khronos/OpenVG.lua → OpenVG.lua
File renamed without changes.
View
0 khronos/OpenVG_Utils.lua → OpenVG_Utils.lua
File renamed without changes.
View
4 cube_texture_and_coords.lua
@@ -3,7 +3,7 @@ local ffi = require "ffi"
-- Spatial coordinates for the cube
-quadx = ffi.new("char[?]", 6*4*3, {
+quadx = ffi.new("GLbyte[?]", 6*4*3, {
-- FRONT
-10, -10, 10,
10, -10, 10,
@@ -42,7 +42,7 @@ quadx = ffi.new("char[?]", 6*4*3, {
});
-- Texture coordinates for the quad.
-texCoords = ffi.new("float[?]", 6 * 4 * 2, {
+texCoords = ffi.new("GLfloat[?]", 6 * 4 * 2, {
0, 0,
0, 1,
1, 0,
View
0 khronos/egl.lua → egl.lua
File renamed without changes.
View
32 khronos/egl_utils.lua → egl_utils.lua
@@ -16,7 +16,6 @@ EglDisplay_mt = {
}
EglDisplay.new = function(api, dispid)
- api = api or EGL.EGL_OPENVG_API
local dpy
if not dispid then
@@ -32,9 +31,13 @@ EglDisplay.new = function(api, dispid)
setmetatable(obj, EglDisplay_mt);
obj:Initialize();
- obj:BindToAPI(api);
- obj:ChooseConfig();
- obj:CreateContext();
+
+ if api then
+ -- api = api or EGL.EGL_OPENVG_API
+ assert(obj:BindToAPI(api), "Could not bind to API");
+ end
+ assert(obj:ChooseConfig(), "Could not choose config");
+ assert(obj:CreateContext(), "Could not create context");
return obj
end
@@ -46,7 +49,7 @@ end
EglDisplay.Initialize = function(self)
local pmajor = ffi.new("EGLint[1]");
local pminor = ffi.new("EGLint[1]");
- local res = EGL.Lib.eglInitialize(self.Handle, pmajor, pminor);
+ local res = EGL.Lib.eglInitialize(self.Handle, nil, nil);
assert(res ~= EGL.EGL_FALSE);
return self, pmajor[0], pminor[0];
@@ -70,17 +73,22 @@ EglDisplay.ChooseConfig = function(self, attribute_list)
EGL.EGL_GREEN_SIZE, 8,
EGL.EGL_BLUE_SIZE, 8,
EGL.EGL_ALPHA_SIZE, 8,
- EGL.EGL_SURFACE_TYPE, EGL.EGL_WINDOW_BIT,
+ EGL.EGL_SURFACE_TYPE, EGL.EGL_WINDOW_BIT,
EGL.EGL_NONE);
- local pconfig = ffi.new("EGLConfig[1]");
+ local pconfig = ffi.new("EGLConfig[10]");
local pnum_config = ffi.new("EGLint[1]");
- local res = EGL.Lib.eglChooseConfig(self.Handle, attribute_list, pconfig, 1, pnum_config);
-
+ local res = EGL.Lib.eglChooseConfig(self.Handle, attribute_list, pconfig, 10, pnum_config);
+
assert(res == EGL.EGL_TRUE);
+ local num_config = pnum_config[0]
+ print("EglDisplay.ChooseConfig(): num: ", num_config);
+
self.Config = pconfig[0];
+
+ return self.Config;
end
EglDisplay.CreateContext = function(self, config)
@@ -111,8 +119,10 @@ EglDisplay.MakeCurrent = function(self, surface, context)
end
EglDisplay.SwapBuffers = function(self, surface)
- surface = surface or self.Surface;
- local res = EGL.Lib.eglSwapBuffers(self.Handle, surface);
+ surface = surface or self.Surface;
+ local res = EGL.Lib.eglSwapBuffers(self.Handle, surface);
+
+ return res;
end
View
4 khronos/eglplatform.lua → eglplatform.lua
@@ -1,9 +1,11 @@
---#include "../KHR/khrplatform.h"
local ffi = require "ffi"
+require "khrplatform"
+
+
ffi.cdef[[
typedef void *EGLNativeDisplayType;
typedef void *EGLNativePixmapType;
View
0 khronos/gl.lua → gl.lua
File renamed without changes.
View
0 khronos/gl2.lua → gl2.lua
File renamed without changes.
View
0 khronos/gl2ext.lua → gl2ext.lua
File renamed without changes.
View
0 khronos/glext.h → glext.h
File renamed without changes.
View
0 vcinclude/common.lua → interface/common.lua
File renamed without changes.
View
0 interface/vmcs_host/vc_cec.lua → interface/vc_cec.lua
File renamed without changes.
View
0 interface/vmcs_host/vc_cecservice.lua → interface/vc_cecservice.lua
File renamed without changes.
View
0 interface/vmcs_host/vc_dispmanx.lua → interface/vc_dispmanx.lua
File renamed without changes.
View
0 interface/vmcs_host/vc_dispmanx_types.lua → interface/vc_dispmanx_types.lua
File renamed without changes.
View
0 ...rface/vmcs_host/vc_dispservice_x_defs.lua → interface/vc_dispservice_x_defs.lua
File renamed without changes.
View
0 interface/vmcs_host/vc_hdmi.lua → interface/vc_hdmi.lua
File renamed without changes.
View
0 interface/vmcs_host/vc_hdmi_property.lua → interface/vc_hdmi_property.lua
File renamed without changes.
View
0 interface/vmcs_host/vc_tvservice.lua → interface/vc_tvservice.lua
File renamed without changes.
View
0 interface/vmcs_host/vc_tvservice_defs.lua → interface/vc_tvservice_defs.lua
File renamed without changes.
View
0 interface/vmcs_host/vcgencmd.lua → interface/vcgencmd.lua
File renamed without changes.
View
1 interface/vctypes/vc_image_types.lua
@@ -7,7 +7,6 @@ local ffi = require "ffi"
This file gets included by the VCE compiler, which gets confused
easily by the VCOS headers. So cannot include vcos.h here.
--]]
---require "../vcos/vcos_stdint"
ffi.cdef[[
/* We have so many rectangle types; let's try to introduce a common one. */
View
0 khronos/khrplatform.lua → khrplatform.lua
File renamed without changes.
View
9 rpiui.lua
@@ -1,13 +1,8 @@
-package.path = package.path..";khronos/?.lua"
-
local ffi = require "ffi"
local BCMHost = require "BcmHost"
-require "khrplatform"
-
-
--[[
GLESv2 must be loaded before EGL or there will be
@@ -18,7 +13,7 @@ require "khrplatform"
to be loaded first.
--]]
local GLESv1 = require "GLESMan"
-local GLESv2 = require "GLES2Man";
+--local GLESv2 = require "GLES2Man";
local EGL = require "egl_utils";
@@ -36,7 +31,7 @@ return {
BCMHost = BCMHost;
GLES = GLESv1;
- GLES2 = GLESv2;
+-- GLES2 = GLESv2;
EGL = EGL;
OpenVG = OpenVG;
View
187 test_egles_basic.lua
@@ -0,0 +1,187 @@
+
+
+-- A rotating cube rendered with OpenGL|ES. Three images used as textures on the cube faces.
+
+local ffi = require "ffi"
+local bit = require "bit"
+local lshift = bit.lshift
+local rshift = bit.rshift
+
+local DMX = require "DisplayManX"
+
+local rpiui = require "rpiui"
+
+local GLES = rpiui.GLES
+local EGL = rpiui.EGL
+local OpenVG = rpiui.OpenVG;
+
+
+
+--local egldisplay = EGL.Display.new(EGL.EGL_OPENGL_ES_API);
+local egldisplay = EGL.Display.new();
+assert(egldisplay, "EglDisplay not created");
+
+local dmxdisplay = DMX.DMXDisplay();
+assert(dmxdisplay, "Could not initialize DMXDisplay");
+
+
+local screenWidth = 320;
+local screenHeight = 240;
+
+
+local IMAGE_SIZE = 128;
+
+--[[
+/***********************************************************
+ * Name: init_ogl
+ *
+ * Arguments:
+ * CUBE_STATE_T *state - holds OGLES model info
+ *
+ * Description: Sets the display, OpenGL|ES context and screen stuff
+ *
+ * Returns: void
+ *
+ ***********************************************************/
+--]]
+
+function createNativeWindow(dmxdisplay, width, height)
+
+ local dst_rect = VC_RECT_T(0,0,width, height);
+ local src_rect = VC_RECT_T(0,0, lshift(width, 16), lshift(height,16));
+
+ --local alpha = VC_DISPMANX_ALPHA_T(ffi.C.DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS,255,0);
+ --local dmxview = dmxdisplay:CreateElement(dst_rect, nil, src_rect, 0, DISPMANX_PROTECTION_NONE, alpha);
+ local dmxview = dmxdisplay:CreateElement(dst_rect, nil, src_rect);
+ assert(dmxview, "FAILURE: Did not create dmxview");
+
+ -- create an EGL window surface
+ local nativewindow = ffi.new("EGL_DISPMANX_WINDOW_T");
+ nativewindow.element = dmxview.Handle;
+ nativewindow.width = width;
+ nativewindow.height = height;
+
+ return nativewindow;
+end
+
+
+function init_ogl(state)
+
+ -- Get size of the display window
+ state.screen_width, state.screen_height = dmxdisplay:GetSize();
+ state.screen_width = screenWidth;
+ state.screen_height = screenHeight;
+ print("SCREEN SIZE: ", state.screen_width, state.screen_height);
+
+ -- Setup the EGL Display
+ state.display = egldisplay;
+
+ state.nativewindow = createNativeWindow(dmxdisplay, state.screen_width, state.screen_height);
+ state.surface = egldisplay:CreateWindowSurface(state.nativewindow);
+ print("SURFACE: ", state.surface);
+
+ -- connect the context to the surface
+ state.display:MakeCurrent();
+
+ -- Set background color and clear buffers
+ glClearColor(0.15, 0.25, 0.35, 1.0);
+ glClear( GL_COLOR_BUFFER_BIT );
+ glClear( GL_DEPTH_BUFFER_BIT );
+end
+
+
+
+
+
+
+
+--[[
+***********************************************************
+* Name: init_model_proj
+*
+* Arguments:
+* CUBE_STATE_T *state - holds OGLES model info
+*
+* Description: Sets the OpenGL|ES model to default values
+*
+* Returns: void
+*
+**********************************************************
+--]]
+function init_model_proj(state)
+
+ local nearp = 1.0;
+ local farp = 500.0;
+ local hht;
+ local hwd;
+
+ glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
+
+ glViewport(0, 0, state.screen_width, state.screen_height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+ hht = nearp * math.tan(45.0 / 2.0 / 180.0 * math.pi);
+ hwd = hht * state.screen_width / state.screen_height;
+
+ glFrustumf(-hwd, hwd, -hht, hht, nearp, farp);
+
+
+ reset_model(state);
+end
+
+
+
+
+--[[
+/***********************************************************
+ * Name: redraw_scene
+ *
+ * Arguments:
+ * CUBE_STATE_T *state - holds OGLES model info
+ *
+ * Description: Draws the model and calls eglSwapBuffers
+ * to render to screen
+ *
+ * Returns: void
+ *
+ ***********************************************************/
+--]]
+function redraw_scene(state)
+
+ -- Start with a clear screen
+ glClear( GL_COLOR_BUFFER_BIT );
+ glClear( GL_DEPTH_BUFFER_BIT );
+
+ glFlush();
+
+ print("SWAP: ", state.display:SwapBuffers());
+end
+
+
+
+-- ==============================================================================
+
+function main()
+ -- Clear application state
+ local state = {
+ distance_inc = 0,
+ }
+
+ -- Start OGLES
+ init_ogl(state);
+
+ redraw_scene(state);
+
+ redraw_scene(state);
+
+ -- Sleep for a second so we can see the results
+ local seconds = 5
+ print( string.format("Sleeping for %d seconds...", seconds ));
+ ffi.C.sleep( seconds )
+
+ return 0;
+end
+
+main();
View
46 test_triangle.lua
@@ -7,24 +7,31 @@ local bit = require "bit"
local lshift = bit.lshift
local rshift = bit.rshift
+local DMX = require "DisplayManX"
+
local rpiui = require "rpiui"
+
local GLES = rpiui.GLES
local EGL = rpiui.EGL
+local OpenVG = rpiui.OpenVG;
-local DMX = require "DisplayManX"
require "cube_texture_and_coords";
-local egldisplay = EGL.Display.new(EGL.EGL_OPENGL_ES_API);
---local egldisplay = EGL.Display.new();
+--local egldisplay = EGL.Display.new(EGL.EGL_OPENGL_ES_API);
+local egldisplay = EGL.Display.new();
assert(egldisplay, "EglDisplay not created");
local dmxdisplay = DMX.DMXDisplay();
assert(dmxdisplay, "Could not initialize DMXDisplay");
+local screenWidth = 640;
+local screenHeight = 480;
+
+
local IMAGE_SIZE = 128;
--[[
@@ -46,6 +53,8 @@ function createNativeWindow(dmxdisplay, width, height)
local dst_rect = VC_RECT_T(0,0,width, height);
local src_rect = VC_RECT_T(0,0, lshift(width, 16), lshift(height,16));
+ --local alpha = VC_DISPMANX_ALPHA_T(ffi.C.DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS,255,0);
+ --local dmxview = dmxdisplay:CreateElement(dst_rect, nil, src_rect, 0, DISPMANX_PROTECTION_NONE, alpha);
local dmxview = dmxdisplay:CreateElement(dst_rect, nil, src_rect);
assert(dmxview, "FAILURE: Did not create dmxview");
@@ -63,13 +72,16 @@ function init_ogl(state)
-- Get size of the display window
state.screen_width, state.screen_height = dmxdisplay:GetSize();
+ state.screen_width = screenWidth;
+ state.screen_height = screenHeight;
print("SCREEN SIZE: ", state.screen_width, state.screen_height);
-- Setup the EGL Display
state.display = egldisplay;
+
state.nativewindow = createNativeWindow(dmxdisplay, state.screen_width, state.screen_height);
state.surface = egldisplay:CreateWindowSurface(state.nativewindow);
- print("SURFACE: ", state.surface, err);
+ print("SURFACE: ", state.surface);
-- connect the context to the surface
state.display:MakeCurrent();
@@ -210,7 +222,7 @@ function reset_model(state)
state.rot_angle_x = 45;
state.rot_angle_y = 30;
state.rot_angle_z = 0;
- state.rot_angle_x_inc = 0.5;
+ state.rot_angle_x_inc = 0;
state.rot_angle_y_inc = 0.5;
state.rot_angle_z_inc = 0;
@@ -230,12 +242,11 @@ end
*
**********************************************************
--]]
+
function init_model_proj(state)
local nearp = 1.0;
local farp = 500.0;
- local hht;
- local hwd;
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
@@ -244,8 +255,8 @@ function init_model_proj(state)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- hht = nearp * math.tan(45.0 / 2.0 / 180.0 * math.pi);
- hwd = hht * state.screen_width / state.screen_height;
+ local hht = nearp * math.tan(45.0 / 2.0 / 180.0 * math.pi);
+ local hwd = hht * state.screen_width / state.screen_height;
glFrustumf(-hwd, hwd, -hht, hht, nearp, farp);
@@ -393,10 +404,12 @@ function redraw_scene(state)
glRotatef(90, 0, 0, 1 ); -- back face normal along z axis
glDrawArrays( GL_TRIANGLE_STRIP, 4, 4);
+
glBindTexture(GL_TEXTURE_2D, state.tex[2]);
glRotatef(90, 1, 0, 0 ); -- left face normal along x axis
glDrawArrays( GL_TRIANGLE_STRIP, 8, 4);
+
glBindTexture(GL_TEXTURE_2D, state.tex[3]);
glRotatef(90, 1, 0, 0 ); -- right face normal along x axis
glDrawArrays( GL_TRIANGLE_STRIP, 12, 4);
@@ -413,6 +426,7 @@ function redraw_scene(state)
glDisable(GL_TEXTURE_2D);
+
state.display:SwapBuffers();
end
@@ -440,7 +454,17 @@ function main()
-- Clear application state
local state = {
- distance_inc = 0,
+ -- model rotation vector and direction
+ rot_angle_x_inc = 0;
+ rot_angle_y_inc = 0;
+ rot_angle_z_inc = 0;
+ -- current model rotation angles
+ rot_angle_x = 0;
+ rot_angle_y = 0;
+ rot_angle_z = 0;
+ -- current distance from camera
+ distance = 0;
+ distance_inc = 0;
}
-- Start OGLES
@@ -454,7 +478,7 @@ function main()
while not terminate do
- --usleep(5*1000);
+ ffi.C.sleep(1);
update_model(state);
redraw_scene(state);
end
View
0 khronos/vgext.lua → vgext.lua
File renamed without changes.
View
0 khronos/vgu.lua → vgu.lua
File renamed without changes.

0 comments on commit eed00a1

Please sign in to comment.