dey-examples: add opengl example apps for mx6
https://jira.digi.com/browse/DEL-804 Signed-off-by: Javier Viguera <javier.viguera@digi.com>
This commit is contained in:
parent
68883946ec
commit
3ac3f03242
|
|
@ -5,7 +5,7 @@ SECTION = "examples"
|
|||
LICENSE = "GPL-2.0"
|
||||
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6"
|
||||
|
||||
DEPENDS = "virtual/egl virtual/libgles1 virtual/libgles2 virtual/kernel"
|
||||
DEPENDS = "virtual/egl virtual/libgles1 virtual/libgles2"
|
||||
|
||||
PR = "${DISTRO}.r0"
|
||||
|
||||
|
|
@ -13,21 +13,19 @@ SRC_URI = "file://opengles"
|
|||
|
||||
S = "${WORKDIR}/opengles"
|
||||
|
||||
do_compile() {
|
||||
${CC} -O2 -Wall -Ilib/include es20_example.c lib/fslutil/fslutil.c -lm -lEGL -lGLESv2 -o es20_example
|
||||
${CC} -O2 -Wall -Ilib/include es11_example.c lib/fslutil/fslutil.c lib/glu3/glu3.c -lm -lEGL -lGLESv1_CM -o es11_example
|
||||
}
|
||||
EXTRA_OEMAKE = ""
|
||||
EXTRA_OEMAKE_mx6 = "EGL_FLAVOUR=${@base_conditional('HAVE_GUI', '1' , 'x11', 'fb', d)}"
|
||||
|
||||
do_install () {
|
||||
install -d ${D}${bindir} ${D}/usr/share/wallpapers
|
||||
install -m 0755 es20_example es11_example ${D}${bindir}
|
||||
install -m 0644 texture.bmp ${D}/usr/share/wallpapers
|
||||
oe_runmake DEST_DIR="${D}" install
|
||||
}
|
||||
|
||||
FILES_${PN} += "/usr/share/wallpapers/texture.bmp"
|
||||
FILES_${PN} = "/opt/${PN}"
|
||||
FILES_${PN}-dbg += "/opt/${PN}/.debug"
|
||||
|
||||
RDEPENDS_${PN} = "lib2dz160-mx51 lib2dz430-mx51"
|
||||
RDEPENDS_${PN}_mx5 = "lib2dz160-mx51 lib2dz430-mx51"
|
||||
RDEPENDS_${PN}_mx6 = "libopenvg-mx6"
|
||||
|
||||
PACKAGE_ARCH = "${MACHINE_ARCH}"
|
||||
|
||||
COMPATIBLE_MACHINE = "(ccimx51js|ccimx53js)"
|
||||
COMPATIBLE_MACHINE = "(ccimx51js|ccimx53js|ccimx6adpt|ccimx6sbc)"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
CFLAGS += -O2 -Ilib/include
|
||||
VPATH = lib/fslutil lib/glu3
|
||||
BINARIES = es20_example es11_example
|
||||
|
||||
all: $(BINARIES)
|
||||
|
||||
es11_example: fslutil.o glu3.o
|
||||
$(CC) $(CFLAGS) $^ -lm -lEGL -lGLESv1_CM $@.c -o $@
|
||||
|
||||
es20_example: fslutil.o
|
||||
$(CC) $(CFLAGS) $^ -lm -lEGL -lGLESv2 $@.c -o $@
|
||||
|
||||
install: $(BINARIES)
|
||||
-mkdir -p $(DEST_DIR)/opt/dey-examples-opengles
|
||||
install -m 0755 $^ $(DEST_DIR)/opt/dey-examples-opengles
|
||||
install -m 0644 texture.bmp $(DEST_DIR)/opt/dey-examples-opengles
|
||||
|
|
@ -51,7 +51,7 @@ int LoadGLTextures()
|
|||
}
|
||||
|
||||
/* Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit */
|
||||
if (ImageLoad("/usr/share/wallpapers/texture.bmp", image1)) {
|
||||
if (ImageLoad("texture.bmp", image1)) {
|
||||
/* Create The Texture */
|
||||
glGenTextures(1, texture);
|
||||
/* Typical Texture Generation Using Data From The Bitmap */
|
||||
|
|
@ -231,7 +231,7 @@ int LoadGLTextures()
|
|||
}
|
||||
|
||||
/* Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit */
|
||||
if (ImageLoad("/usr/share/wallpapers/texture.bmp", image1)) {
|
||||
if (ImageLoad("texture.bmp", image1)) {
|
||||
/* Create The Texture */
|
||||
glGenTextures(1, texture);
|
||||
/* Typical Texture Generation Using Data From The Bitmap */
|
||||
|
Before Width: | Height: | Size: 192 KiB After Width: | Height: | Size: 192 KiB |
|
|
@ -0,0 +1,27 @@
|
|||
CFLAGS += -O2 -Icommon/inc -DLINUX
|
||||
VPATH = common/src
|
||||
BINARIES = es20_example es11_example
|
||||
|
||||
ifeq ($(EGL_FLAVOUR),fb)
|
||||
$(info BUILDING FOR FB)
|
||||
CFLAGS += -DEGL_API_FB
|
||||
else ifeq ($(EGL_FLAVOUR),x11)
|
||||
$(info BUILDING FOR X11)
|
||||
CFLAGS += -DEGL_USE_X11
|
||||
X11LIBS = -lX11
|
||||
else
|
||||
$(error Platform not recognized)
|
||||
endif
|
||||
|
||||
all: $(BINARIES)
|
||||
|
||||
es11_example: fsl_egl.o fslutil.o glu3.o
|
||||
$(CC) $(CFLAGS) $^ -lm -lEGL -lGLESv1_CM $(X11LIBS) $@.c -o $@
|
||||
|
||||
es20_example: fsl_egl.o fslutil.o
|
||||
$(CC) $(CFLAGS) $^ -lm -lEGL -lGLESv2 $(X11LIBS) $@.c -o $@
|
||||
|
||||
install: $(BINARIES)
|
||||
-mkdir -p $(DEST_DIR)/opt/dey-examples-opengles
|
||||
install -m 0755 $^ $(DEST_DIR)/opt/dey-examples-opengles
|
||||
install -m 0644 texture.bmp $(DEST_DIR)/opt/dey-examples-opengles
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/****************************************************************************
|
||||
* Copyright (c) 2012 Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the Freescale Semiconductor, Inc. nor the names of
|
||||
* its contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Labels parameters
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef _FSL_EGL_H_
|
||||
#define _FSL_EGL_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <EGL/egl.h>
|
||||
|
||||
EGLNativeDisplayType fsl_getNativeDisplay();
|
||||
EGLNativeWindowType fsl_createwindow(EGLDisplay egldisplay, EGLNativeDisplayType eglNativeDisplayType);
|
||||
void fsl_destroywindow(EGLNativeWindowType eglNativeWindowType,EGLNativeDisplayType eglNativeDisplayType);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif //_FSL_EGL_H_
|
||||
|
||||
|
|
@ -0,0 +1,224 @@
|
|||
/****************************************************************************
|
||||
* Copyright (c) 2012 Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the Freescale Semiconductor, Inc. nor the names of
|
||||
* its contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Labels parameters
|
||||
|
||||
*****************************************************************************/
|
||||
#ifndef _FSLUTIL_H_
|
||||
#define _FSLUTIL_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Values for reading in ATC compressed texture files
|
||||
#define GL_ATC_RGB_AMD 0x8C92
|
||||
#define GL_ATC_RGBA_AMD 0x8C93
|
||||
#define ATC_SIGNATURE 0xCCC40002
|
||||
#define ATI1N_SIGNATURE 0x31495441
|
||||
#define ATI2N_SIGNATURE 0x32495441
|
||||
#define ETC_SIGNATURE 0xEC000001
|
||||
#define ATC_RGB 0x00000001
|
||||
#define ATC_RGBA 0x00000002
|
||||
#define ATC_TILED 0X00000004
|
||||
#define ATC_ALPHA_INTERPOLATED 0X00000010
|
||||
|
||||
#define PI_OVER_360 0.00872664f
|
||||
|
||||
#ifndef fslBool
|
||||
#define fslBool int
|
||||
#define FSL_FALSE 0
|
||||
#define FSL_TRUE !FSL_FALSE
|
||||
#endif
|
||||
|
||||
#define FSL_POINTER_MAX 10000
|
||||
|
||||
|
||||
/* Image type - contains height, width, and data */
|
||||
typedef struct Image_s {
|
||||
unsigned long sizeX;
|
||||
unsigned long sizeY;
|
||||
char *data;
|
||||
int Format;
|
||||
} Image;
|
||||
|
||||
|
||||
typedef enum fslStatus_e
|
||||
{
|
||||
FSL_STATUS_DEVICE_ERROR = -5, //could not open a hardware device driver
|
||||
FSL_STATUS_NO_CONTEXT = -4, //something has caused a device to fail and loose context
|
||||
FSL_STATUS_BAD_PARAMETER = -3,
|
||||
FSL_STATUS_ALLOCATION_ISSUE = -2,
|
||||
FSL_STATUS_UNSUPPORTED_FEATURE = -1,
|
||||
FSL_STATUS_GENERAL_ERROR = 0,
|
||||
FSL_STATUS_SUCCESS = 1,
|
||||
FSL_FSLSTATUS_END = 0xFFFFFFFF, //This forces the data type for binary lib compatipility
|
||||
} fslStatus;
|
||||
|
||||
typedef enum fslAxis_e
|
||||
{
|
||||
FSL_X_AXIS, FSL_Y_AXIS, FSL_Z_AXIS
|
||||
} fslAxis;
|
||||
|
||||
typedef enum fslInputType_e
|
||||
{
|
||||
FSL_INPUT_KEYPRESS =1000,
|
||||
FSL_INPUT_KEYRELEASE =1500,
|
||||
FSL_INPUT_POINTERDOWN =2000,
|
||||
FSL_INPUT_POINTERUP =3000,
|
||||
FSL_INPUT_POINTERMOVE =4000,
|
||||
FSL_INPUT_STOP =5000,
|
||||
FSL_INPUT_PLAY =5001,
|
||||
FSL_INPUT_PAUSE =5002,
|
||||
FSL_INPUT_REW =5003,
|
||||
FSL_INPUT_FFWD =5004,
|
||||
FSL_INPUT_SEEK =5005,
|
||||
FSL_INPUT_CLOSEWINDOW =6000,
|
||||
FSL_INPUTTYPE_END =0xFFFFFFFF,
|
||||
} fslInputType;
|
||||
|
||||
typedef struct fslInputEventType_s
|
||||
{
|
||||
fslInputType input;
|
||||
unsigned int signalA; //X, keystroke 1 Coordinates range from 0 to FSL_POINTER_MAX; 0,0 lower left corner
|
||||
unsigned int signalB; //Y, keystroke 2
|
||||
unsigned int signalC; //undefined, could be pointer enumerator for multi-touch / secondary input
|
||||
long time; //in microseconds
|
||||
} fslInputEventType;
|
||||
|
||||
typedef enum fslInputDevice_e
|
||||
{
|
||||
FSL_INPUTDEVICE_TOUCHSCREEN =1000,
|
||||
FSL_INPUTDEVICETYPE_END =0xFFFFFFFF,
|
||||
} fslInputDevice;
|
||||
|
||||
typedef void* fslDeviceHandle;
|
||||
|
||||
#define FSL_UTIL_MAX_FILE_NAME_LENGTH 1024 // This is arbitrary
|
||||
#define FSL_INPUT_MAX_EVENTS 64
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <malloc.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <linux/input.h>
|
||||
|
||||
#ifdef FSL_EGL_USE_X11
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/Xcomposite.h>
|
||||
#include <X11/extensions/render.h>
|
||||
#include <X11/extensions/Xrender.h>
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Name: fslLoadCTES
|
||||
// Desc: Helper function to load an compressed image file (ATC, ETC, etc.) from the compressenator
|
||||
//--------------------------------------------------------------------------------------
|
||||
char* fslLoadCTES( char* strFileName, unsigned int* pWidth, unsigned int* pHeight, unsigned int* nFormat, unsigned int* nSize );
|
||||
|
||||
//fslLoadBMP
|
||||
fslBool fslInit2DBMPTextureGL(char *,unsigned int *pTextureHandle);
|
||||
|
||||
//fslLoadTGA
|
||||
fslBool fslInit2DTGATextureGL(char* strFileName, unsigned int *pTextureHandle);
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Name: fslEGLCheck
|
||||
// Desc: Helper function to print EGL errors and exits application
|
||||
//--------------------------------------------------------------------------------------
|
||||
fslBool fslEGLCheck( fslBool bExitOnFailure );
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Name: fslInit2DCTESTextureGL
|
||||
// Desc: Helper function to load a CTES texture file and bind it to a given GL texture handle
|
||||
//--------------------------------------------------------------------------------------
|
||||
fslBool fslInit2DCTESTextureGL( char* strFileName, unsigned int *pTextureHandle );
|
||||
|
||||
#ifdef FSL_EGL_USE_X11
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Name: fslLoadFontX
|
||||
// Desc: Helper function to load a X11 font into given struct
|
||||
//--------------------------------------------------------------------------------------
|
||||
void fslLoadFontX( Display *display, XFontStruct **font_info );
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Name: fslErrorHandlerX
|
||||
// Desc: Helper function to print incoming X11 server errors
|
||||
//--------------------------------------------------------------------------------------
|
||||
int fslErrorHandlerX( Display *display, XErrorEvent *error );
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Name: fslGetTickCount
|
||||
// Desc: Helper function to get current time
|
||||
//--------------------------------------------------------------------------------------
|
||||
unsigned int fslGetTickCount();
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Name: fslMulMatrix4x4
|
||||
// Desc: 4x4 Matix Muliply DEPRECATED for GLU
|
||||
//--------------------------------------------------------------------------------------
|
||||
void fslMultMatrix4x4( float *matC, float *matA, float *matB);
|
||||
|
||||
fslBool fslInvertMatrix4x4( float *matA, float *matC);
|
||||
|
||||
void fslPerspectiveMatrix4x4 ( float *m, float fov, float aspect, float zNear, float zFar);
|
||||
|
||||
void fslMultMatrix4x4Vec4x1 ( float *matA, float *vecA, float *vecB );
|
||||
|
||||
void fslRotateMatrix4x4 (float *m, float angle, fslAxis axis);
|
||||
|
||||
void fslTranslateMatrix4x4 (float *m, float transX, float transY, float transZ);
|
||||
|
||||
void fslScaleMatrix4x4 (float *m, float scaleX, float scaleY, float scaleZ);
|
||||
void fslNormalize(float *v);
|
||||
void fslLoadIdentityMatrix4x4 (float *m);
|
||||
void fslPrintMatrix4x4(float *m);
|
||||
fslBool fslUnProject(float winx,float winy, float winz, float modelMatrix[16], float projMatrix[16], int viewport[4], float *objx, float *objy, float *objz);
|
||||
void fslCrossProduct(float *result, float *b, float* c);
|
||||
void fslDirectionVector(float *result, float *endPoint, float *startPoint);
|
||||
float fslInnerProduct( float *v, float *q);
|
||||
int fslRayIntersectsTriangle(float *p, float *d,float *v0, float *v1, float *v2);
|
||||
int LoadBMP(char *filename, Image *image);
|
||||
int LoadTGA(const char *textureFileName, Image *image);
|
||||
void fslCalculateNormals(float *triArray, int size, float *normArray);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif //_FSLUTIL_H_
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,396 @@
|
|||
/*
|
||||
* Copyright © 2009 Ian D. Romanick
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define INLINE __forceinline
|
||||
#elif defined(__GNUC_GNU_INLINE__) || defined(__GNUC_STDC_INLINE__)
|
||||
# define INLINE inline __attribute__((gnu_inline))
|
||||
#else
|
||||
# define INLINE inline
|
||||
#endif
|
||||
|
||||
extern INLINE void gluMult4v_4v(GLUvec4 *result,
|
||||
const GLUvec4 *v1, const GLUvec4 *v2)
|
||||
{
|
||||
result->values[0] = v1->values[0] * v2->values[0];
|
||||
result->values[1] = v1->values[1] * v2->values[1];
|
||||
result->values[2] = v1->values[2] * v2->values[2];
|
||||
result->values[3] = v1->values[3] * v2->values[3];
|
||||
}
|
||||
|
||||
|
||||
extern INLINE void gluDiv4v_4v(GLUvec4 *result,
|
||||
const GLUvec4 *v1, const GLUvec4 *v2)
|
||||
{
|
||||
result->values[0] = v1->values[0] / v2->values[0];
|
||||
result->values[1] = v1->values[1] / v2->values[1];
|
||||
result->values[2] = v1->values[2] / v2->values[2];
|
||||
result->values[3] = v1->values[3] / v2->values[3];
|
||||
}
|
||||
|
||||
|
||||
extern INLINE void gluAdd4v_4v(GLUvec4 *result,
|
||||
const GLUvec4 *v1, const GLUvec4 *v2)
|
||||
{
|
||||
result->values[0] = v1->values[0] + v2->values[0];
|
||||
result->values[1] = v1->values[1] + v2->values[1];
|
||||
result->values[2] = v1->values[2] + v2->values[2];
|
||||
result->values[3] = v1->values[3] + v2->values[3];
|
||||
}
|
||||
|
||||
|
||||
extern INLINE void gluSub4v_4v(GLUvec4 *result,
|
||||
const GLUvec4 *v1, const GLUvec4 *v2)
|
||||
{
|
||||
result->values[0] = v1->values[0] - v2->values[0];
|
||||
result->values[1] = v1->values[1] - v2->values[1];
|
||||
result->values[2] = v1->values[2] - v2->values[2];
|
||||
result->values[3] = v1->values[3] - v2->values[3];
|
||||
}
|
||||
|
||||
|
||||
extern INLINE void gluMult4v_f(GLUvec4 *result,
|
||||
const GLUvec4 *v1, GLfloat f)
|
||||
{
|
||||
result->values[0] = v1->values[0] * f;
|
||||
result->values[1] = v1->values[1] * f;
|
||||
result->values[2] = v1->values[2] * f;
|
||||
result->values[3] = v1->values[3] * f;
|
||||
}
|
||||
|
||||
|
||||
extern INLINE void gluDiv4v_f(GLUvec4 *result,
|
||||
const GLUvec4 *v1, GLfloat f)
|
||||
{
|
||||
result->values[0] = v1->values[0] / f;
|
||||
result->values[1] = v1->values[1] / f;
|
||||
result->values[2] = v1->values[2] / f;
|
||||
result->values[3] = v1->values[3] / f;
|
||||
}
|
||||
|
||||
|
||||
extern INLINE void gluAdd4v_f(GLUvec4 *result,
|
||||
const GLUvec4 *v1, GLfloat f)
|
||||
{
|
||||
result->values[0] = v1->values[0] + f;
|
||||
result->values[1] = v1->values[1] + f;
|
||||
result->values[2] = v1->values[2] + f;
|
||||
result->values[3] = v1->values[3] + f;
|
||||
}
|
||||
|
||||
|
||||
extern INLINE void gluSub4v_f(GLUvec4 *result,
|
||||
const GLUvec4 *v1, GLfloat f)
|
||||
{
|
||||
result->values[0] = v1->values[0] - f;
|
||||
result->values[1] = v1->values[1] - f;
|
||||
result->values[2] = v1->values[2] - f;
|
||||
result->values[3] = v1->values[3] - f;
|
||||
}
|
||||
|
||||
|
||||
extern INLINE void gluMult4m_f(GLUmat4 *result,
|
||||
const GLUmat4 *m, GLfloat f)
|
||||
{
|
||||
GLUmat4 temp;
|
||||
|
||||
gluMult4v_f(& temp.col[0], & m->col[0], f);
|
||||
gluMult4v_f(& temp.col[1], & m->col[1], f);
|
||||
gluMult4v_f(& temp.col[2], & m->col[2], f);
|
||||
gluMult4v_f(& temp.col[3], & m->col[3], f);
|
||||
*result = temp;
|
||||
}
|
||||
|
||||
|
||||
extern INLINE void gluMult4m_4v(GLUvec4 *result,
|
||||
const GLUmat4 *m, const GLUvec4 *v)
|
||||
{
|
||||
GLUvec4 temp[6];
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
gluMult4v_f(& temp[i], & m->col[i], v->values[i]);
|
||||
}
|
||||
|
||||
gluAdd4v_4v(& temp[4], & temp[0], & temp[1]);
|
||||
gluAdd4v_4v(& temp[5], & temp[2], & temp[3]);
|
||||
gluAdd4v_4v(result, & temp[4], & temp[5]);
|
||||
}
|
||||
|
||||
|
||||
extern INLINE void gluAdd4m_4m(GLUmat4 *result,
|
||||
const GLUmat4 *m1, const GLUmat4 *m2)
|
||||
{
|
||||
GLUmat4 temp;
|
||||
|
||||
gluAdd4v_4v(& temp.col[0], & m1->col[0], & m2->col[0]);
|
||||
gluAdd4v_4v(& temp.col[1], & m1->col[1], & m2->col[1]);
|
||||
gluAdd4v_4v(& temp.col[2], & m1->col[2], & m2->col[2]);
|
||||
gluAdd4v_4v(& temp.col[3], & m1->col[3], & m2->col[3]);
|
||||
*result = temp;
|
||||
}
|
||||
|
||||
extern INLINE void gluSub4m_4m(GLUmat4 *result,
|
||||
const GLUmat4 *m1, const GLUmat4 *m2)
|
||||
{
|
||||
GLUmat4 temp;
|
||||
|
||||
gluSub4v_4v(& temp.col[0], & m1->col[0], & m2->col[0]);
|
||||
gluSub4v_4v(& temp.col[1], & m1->col[1], & m2->col[1]);
|
||||
gluSub4v_4v(& temp.col[2], & m1->col[2], & m2->col[2]);
|
||||
gluSub4v_4v(& temp.col[3], & m1->col[3], & m2->col[3]);
|
||||
*result = temp;
|
||||
}
|
||||
|
||||
extern INLINE GLfloat gluDot4_4v(const GLUvec4 *v1, const GLUvec4 *v2)
|
||||
{
|
||||
return v1->values[0] * v2->values[0]
|
||||
+ v1->values[1] * v2->values[1]
|
||||
+ v1->values[2] * v2->values[2]
|
||||
+ v1->values[3] * v2->values[3];
|
||||
}
|
||||
|
||||
|
||||
extern INLINE GLfloat gluDot3_4v(const GLUvec4 *v1, const GLUvec4 *v2)
|
||||
{
|
||||
return v1->values[0] * v2->values[0]
|
||||
+ v1->values[1] * v2->values[1]
|
||||
+ v1->values[2] * v2->values[2];
|
||||
}
|
||||
|
||||
|
||||
extern INLINE GLfloat gluDot2_4v(const GLUvec4 *v1, const GLUvec4 *v2)
|
||||
{
|
||||
return v1->values[0] * v2->values[0]
|
||||
+ v1->values[1] * v2->values[1];
|
||||
}
|
||||
|
||||
|
||||
extern INLINE void gluCross4v(GLUvec4 *result,
|
||||
const GLUvec4 *v1, const GLUvec4 *v2)
|
||||
{
|
||||
GLUvec4 temp;
|
||||
|
||||
temp.values[0] = (v1->values[1] * v2->values[2])
|
||||
- (v1->values[2] * v2->values[1]);
|
||||
temp.values[1] = (v1->values[2] * v2->values[0])
|
||||
- (v1->values[0] * v2->values[2]);
|
||||
temp.values[2] = (v1->values[0] * v2->values[1])
|
||||
- (v1->values[1] * v2->values[0]);
|
||||
temp.values[3] = 0.0;
|
||||
*result = temp;
|
||||
}
|
||||
|
||||
|
||||
extern INLINE void gluOuter4v(GLUmat4 *result,
|
||||
const GLUvec4 *v1, const GLUvec4 *v2)
|
||||
{
|
||||
GLUmat4 temp;
|
||||
|
||||
gluMult4v_f(& temp.col[0], v1, v2->values[0]);
|
||||
gluMult4v_f(& temp.col[1], v1, v2->values[1]);
|
||||
gluMult4v_f(& temp.col[2], v1, v2->values[2]);
|
||||
gluMult4v_f(& temp.col[3], v1, v2->values[3]);
|
||||
*result = temp;
|
||||
}
|
||||
|
||||
|
||||
extern INLINE GLfloat gluLengthSqr4v(const GLUvec4 *v)
|
||||
{
|
||||
return gluDot4_4v(v, v);
|
||||
}
|
||||
|
||||
|
||||
extern INLINE GLfloat gluLength4v(const GLUvec4 *v)
|
||||
{
|
||||
return (GLfloat) sqrt(gluLengthSqr4v(v));
|
||||
}
|
||||
|
||||
|
||||
extern INLINE void gluNormalize4v(GLUvec4 *result, const GLUvec4 *v)
|
||||
{
|
||||
gluDiv4v_f(result, v, gluLength4v(v));
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern INLINE void gluTranspose4m(GLUmat4 *result, const GLUmat4 *m)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned j;
|
||||
GLUmat4 temp;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
temp.col[i].values[j] = m->col[j].values[i];
|
||||
}
|
||||
}
|
||||
|
||||
*result = temp;
|
||||
}
|
||||
|
||||
|
||||
extern INLINE void gluMult4m_4m(GLUmat4 *result,
|
||||
const GLUmat4 *m1, const GLUmat4 *m2)
|
||||
{
|
||||
GLUmat4 temp;
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
gluMult4m_4v(& temp.col[i], m1, & m2->col[i]);
|
||||
}
|
||||
|
||||
*result = temp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern INLINE void gluTranslate3f(GLUmat4 *result,
|
||||
GLfloat x, GLfloat y, GLfloat z)
|
||||
{
|
||||
memcpy(result, & gluIdentityMatrix, sizeof(gluIdentityMatrix));
|
||||
result->col[3].values[0] = x;
|
||||
result->col[3].values[1] = y;
|
||||
result->col[3].values[2] = z;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern INLINE GLfloat gluDot4(const GLUvec4 &v1, const GLUvec4 &v2)
|
||||
{
|
||||
return v1.values[0] * v2.values[0]
|
||||
+ v1.values[1] * v2.values[1]
|
||||
+ v1.values[2] * v2.values[2]
|
||||
+ v1.values[3] * v2.values[3];
|
||||
}
|
||||
|
||||
|
||||
extern INLINE GLfloat gluDot3(const GLUvec4 &v1, const GLUvec4 &v2)
|
||||
{
|
||||
return v1.values[0] * v2.values[0]
|
||||
+ v1.values[1] * v2.values[1]
|
||||
+ v1.values[2] * v2.values[2];
|
||||
}
|
||||
|
||||
|
||||
extern INLINE GLfloat gluDot2(const GLUvec4 &v1, const GLUvec4 &v2)
|
||||
{
|
||||
return v1.values[0] * v2.values[0]
|
||||
+ v1.values[1] * v2.values[1];
|
||||
}
|
||||
|
||||
|
||||
INLINE GLUvec4 GLUvec4::operator+(const GLUvec4 &v) const
|
||||
{
|
||||
return GLUvec4(values[0] + v.values[0],
|
||||
values[1] + v.values[1],
|
||||
values[2] + v.values[2],
|
||||
values[3] + v.values[3]);
|
||||
}
|
||||
|
||||
|
||||
INLINE GLUvec4 GLUvec4::operator-(const GLUvec4 &v) const
|
||||
{
|
||||
return GLUvec4(values[0] - v.values[0],
|
||||
values[1] - v.values[1],
|
||||
values[2] - v.values[2],
|
||||
values[3] - v.values[3]);
|
||||
}
|
||||
|
||||
|
||||
INLINE GLUvec4 GLUvec4::operator*(const GLUvec4 &v) const
|
||||
{
|
||||
return GLUvec4(values[0] * v.values[0],
|
||||
values[1] * v.values[1],
|
||||
values[2] * v.values[2],
|
||||
values[3] * v.values[3]);
|
||||
}
|
||||
|
||||
|
||||
INLINE GLUvec4 GLUvec4::operator*(GLfloat f) const
|
||||
{
|
||||
return GLUvec4(values[0] * f,
|
||||
values[1] * f,
|
||||
values[2] * f,
|
||||
values[3] * f);
|
||||
}
|
||||
|
||||
|
||||
INLINE GLUvec4 GLUvec4::operator*(const GLUmat4 &m) const
|
||||
{
|
||||
return GLUvec4(gluDot4(*this, m.col[0]),
|
||||
gluDot4(*this, m.col[1]),
|
||||
gluDot4(*this, m.col[2]),
|
||||
gluDot4(*this, m.col[3]));
|
||||
}
|
||||
|
||||
|
||||
INLINE GLUmat4 GLUmat4::operator+(const GLUmat4 &m) const
|
||||
{
|
||||
GLUmat4 temp;
|
||||
|
||||
gluAdd4m_4m(& temp, this, &m);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
INLINE GLUmat4 GLUmat4::operator-(const GLUmat4 &m) const
|
||||
{
|
||||
return GLUmat4(col[0] - m.col[0],
|
||||
col[1] - m.col[1],
|
||||
col[2] - m.col[2],
|
||||
col[3] - m.col[3]);
|
||||
}
|
||||
|
||||
|
||||
INLINE GLUmat4 GLUmat4::operator*(GLfloat f) const
|
||||
{
|
||||
GLUmat4 temp;
|
||||
|
||||
gluMult4m_f(& temp, this, f);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
INLINE GLUvec4 GLUmat4::operator*(const GLUvec4 &v) const
|
||||
{
|
||||
return (col[0] * v.values[0])
|
||||
+ (col[1] * v.values[1])
|
||||
+ (col[2] * v.values[2])
|
||||
+ (col[3] * v.values[3]);
|
||||
}
|
||||
|
||||
|
||||
INLINE GLUmat4 GLUmat4::operator*(const GLUmat4 &m) const
|
||||
{
|
||||
GLUmat4 temp;
|
||||
|
||||
gluMult4m_4m(& temp, this, &m);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
|
@ -0,0 +1,475 @@
|
|||
/****************************************************************************
|
||||
* Copyright (c) 2012 Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the Freescale Semiconductor, Inc. nor the names of
|
||||
* its contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Labels parameters
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <EGL/egl.h>
|
||||
|
||||
#ifdef EGL_USE_X11
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xlib.h>
|
||||
#elif EGL_API_WL
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <linux/input.h>
|
||||
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-egl.h>
|
||||
#include <wayland-cursor.h>
|
||||
|
||||
#include <GLES2/gl2.h>
|
||||
#include <EGL/egl.h>
|
||||
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-egl.h>
|
||||
#include <wayland-cursor.h>
|
||||
|
||||
struct geometry {
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
struct display;
|
||||
|
||||
struct window {
|
||||
struct display *display;
|
||||
struct wl_egl_window *native;
|
||||
struct geometry geometry, window_size;
|
||||
struct wl_surface *surface;
|
||||
struct wl_shell_surface *shell_surface;
|
||||
EGLSurface egl_surface;
|
||||
struct wl_callback *callback;
|
||||
int fullscreen, configured, opaque;
|
||||
};
|
||||
|
||||
struct display {
|
||||
struct wl_display *display;
|
||||
struct wl_registry *registry;
|
||||
struct wl_compositor *compositor;
|
||||
struct wl_shell *shell;
|
||||
struct wl_seat *seat;
|
||||
struct wl_pointer *pointer;
|
||||
struct wl_keyboard *keyboard;
|
||||
struct wl_shm *shm;
|
||||
struct wl_cursor_theme *cursor_theme;
|
||||
struct wl_cursor *default_cursor;
|
||||
struct wl_surface *cursor_surface;
|
||||
struct window *window;
|
||||
};
|
||||
|
||||
struct display sdisplay = { 0 };
|
||||
struct window swindow = { 0 };
|
||||
|
||||
static void
|
||||
create_wl_surface(VOID_ARGUMENT)
|
||||
{
|
||||
struct display * display = &sdisplay;
|
||||
struct window * window = &swindow;
|
||||
|
||||
window->surface = wl_compositor_create_surface(display->compositor);
|
||||
window->shell_surface = wl_shell_get_shell_surface(display->shell,
|
||||
window->surface);
|
||||
|
||||
window->native =
|
||||
wl_egl_window_create(window->surface,
|
||||
window->window_size.width,
|
||||
window->window_size.height);
|
||||
|
||||
wl_shell_surface_set_title(window->shell_surface, "3DMark for GLES2.0");
|
||||
|
||||
wl_shell_surface_set_fullscreen(window->shell_surface,
|
||||
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
|
||||
0, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
configure_callback(void *data, struct wl_callback *callback, uint32_t time)
|
||||
{
|
||||
struct window *window = (struct window *)data;
|
||||
|
||||
wl_callback_destroy(callback);
|
||||
|
||||
window->configured = 1;
|
||||
}
|
||||
|
||||
static struct wl_callback_listener configure_callback_listener = {
|
||||
configure_callback,
|
||||
};
|
||||
|
||||
static void
|
||||
handle_ping(void *data, struct wl_shell_surface *shell_surface,
|
||||
uint32_t serial)
|
||||
{
|
||||
wl_shell_surface_pong(shell_surface, serial);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_configure(void *data, struct wl_shell_surface *shell_surface,
|
||||
uint32_t edges, int32_t width, int32_t height)
|
||||
{
|
||||
struct window *window = (struct window *)data;
|
||||
|
||||
if (window->native)
|
||||
wl_egl_window_resize(window->native, width, height, 0, 0);
|
||||
|
||||
window->geometry.width = width;
|
||||
window->geometry.height = height;
|
||||
|
||||
if (!window->fullscreen)
|
||||
window->window_size = window->geometry;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
|
||||
{
|
||||
}
|
||||
|
||||
static const struct wl_shell_surface_listener shell_surface_listener = {
|
||||
handle_ping,
|
||||
handle_configure,
|
||||
handle_popup_done
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
toggle_fullscreen(struct window *window, int fullscreen)
|
||||
{
|
||||
struct wl_callback *callback;
|
||||
|
||||
window->fullscreen = fullscreen;
|
||||
window->configured = 0;
|
||||
|
||||
if (fullscreen) {
|
||||
wl_shell_surface_set_fullscreen(window->shell_surface,
|
||||
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
|
||||
0, NULL);
|
||||
} else {
|
||||
wl_shell_surface_set_toplevel(window->shell_surface);
|
||||
handle_configure(window, window->shell_surface, 0,
|
||||
window->window_size.width,
|
||||
window->window_size.height);
|
||||
}
|
||||
|
||||
callback = wl_display_sync(window->display->display);
|
||||
wl_callback_add_listener(callback, &configure_callback_listener,
|
||||
window);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
pointer_handle_enter(void *data, struct wl_pointer *pointer,
|
||||
uint32_t serial, struct wl_surface *surface,
|
||||
wl_fixed_t sx, wl_fixed_t sy)
|
||||
{
|
||||
struct display *display = (struct display *)data;
|
||||
struct wl_buffer *buffer;
|
||||
struct wl_cursor *cursor = display->default_cursor;
|
||||
struct wl_cursor_image *image;
|
||||
|
||||
if (display->window->fullscreen)
|
||||
wl_pointer_set_cursor(pointer, serial, NULL, 0, 0);
|
||||
else if (cursor) {
|
||||
image = display->default_cursor->images[0];
|
||||
buffer = wl_cursor_image_get_buffer(image);
|
||||
wl_pointer_set_cursor(pointer, serial,
|
||||
display->cursor_surface,
|
||||
image->hotspot_x,
|
||||
image->hotspot_y);
|
||||
wl_surface_attach(display->cursor_surface, buffer, 0, 0);
|
||||
wl_surface_damage(display->cursor_surface, 0, 0,
|
||||
image->width, image->height);
|
||||
wl_surface_commit(display->cursor_surface);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pointer_handle_leave(void *data, struct wl_pointer *pointer,
|
||||
uint32_t serial, struct wl_surface *surface)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
pointer_handle_motion(void *data, struct wl_pointer *pointer,
|
||||
uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
|
||||
uint32_t serial, uint32_t time, uint32_t button,
|
||||
uint32_t state)
|
||||
{
|
||||
struct display *display = (struct display *)data;
|
||||
|
||||
if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED)
|
||||
wl_shell_surface_move(display->window->shell_surface,
|
||||
display->seat, serial);
|
||||
}
|
||||
|
||||
static void
|
||||
pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
|
||||
uint32_t time, uint32_t axis, wl_fixed_t value)
|
||||
{
|
||||
}
|
||||
|
||||
static const struct wl_pointer_listener pointer_listener = {
|
||||
pointer_handle_enter,
|
||||
pointer_handle_leave,
|
||||
pointer_handle_motion,
|
||||
pointer_handle_button,
|
||||
pointer_handle_axis,
|
||||
};
|
||||
|
||||
static void
|
||||
keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
|
||||
uint32_t format, int fd, uint32_t size)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
|
||||
uint32_t serial, struct wl_surface *surface,
|
||||
struct wl_array *keys)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
|
||||
uint32_t serial, struct wl_surface *surface)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
|
||||
uint32_t serial, uint32_t time, uint32_t key,
|
||||
uint32_t state)
|
||||
{
|
||||
struct display *d = (struct display *)data;
|
||||
|
||||
if (key == KEY_F11 && state)
|
||||
toggle_fullscreen(d->window, d->window->fullscreen ^ 1);
|
||||
}
|
||||
|
||||
static void
|
||||
keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
|
||||
uint32_t serial, uint32_t mods_depressed,
|
||||
uint32_t mods_latched, uint32_t mods_locked,
|
||||
uint32_t group)
|
||||
{
|
||||
}
|
||||
|
||||
static const struct wl_keyboard_listener keyboard_listener = {
|
||||
keyboard_handle_keymap,
|
||||
keyboard_handle_enter,
|
||||
keyboard_handle_leave,
|
||||
keyboard_handle_key,
|
||||
keyboard_handle_modifiers,
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
seat_handle_capabilities(void *data, struct wl_seat *seat,
|
||||
uint32_t caps)
|
||||
{
|
||||
struct display *d = (struct display *)data;
|
||||
|
||||
if ((caps & WL_SEAT_CAPABILITY_POINTER) && !d->pointer) {
|
||||
d->pointer = wl_seat_get_pointer(seat);
|
||||
wl_pointer_add_listener(d->pointer, &pointer_listener, d);
|
||||
} else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && d->pointer) {
|
||||
wl_pointer_destroy(d->pointer);
|
||||
d->pointer = NULL;
|
||||
}
|
||||
|
||||
if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !d->keyboard) {
|
||||
d->keyboard = wl_seat_get_keyboard(seat);
|
||||
wl_keyboard_add_listener(d->keyboard, &keyboard_listener, d);
|
||||
} else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && d->keyboard) {
|
||||
wl_keyboard_destroy(d->keyboard);
|
||||
d->keyboard = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static const struct wl_seat_listener seat_listener = {
|
||||
seat_handle_capabilities,
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
registry_handle_global(void *data, struct wl_registry *registry,
|
||||
uint32_t name, const char *interface, uint32_t version)
|
||||
{
|
||||
struct display *d = (struct display *)data;
|
||||
|
||||
if (strcmp(interface, "wl_compositor") == 0) {
|
||||
d->compositor =
|
||||
(struct wl_compositor*)wl_registry_bind(registry, name,&wl_compositor_interface, 1);
|
||||
} else if (strcmp(interface, "wl_shell") == 0) {
|
||||
d->shell = (struct wl_shell *)wl_registry_bind(registry, name,
|
||||
&wl_shell_interface, 1);
|
||||
} else if (strcmp(interface, "wl_seat") == 0) {
|
||||
d->seat = (struct wl_seat *)wl_registry_bind(registry, name,
|
||||
&wl_seat_interface, 1);
|
||||
wl_seat_add_listener(d->seat, &seat_listener, d);
|
||||
} else if (strcmp(interface, "wl_shm") == 0) {
|
||||
d->shm = (struct wl_shm *)wl_registry_bind(registry, name,
|
||||
&wl_shm_interface, 1);
|
||||
d->cursor_theme = wl_cursor_theme_load(NULL, 32, d->shm);
|
||||
d->default_cursor =
|
||||
wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr");
|
||||
}
|
||||
}
|
||||
|
||||
static const struct wl_registry_listener registry_listener = {
|
||||
registry_handle_global
|
||||
};
|
||||
#endif
|
||||
|
||||
EGLNativeDisplayType fsl_getNativeDisplay()
|
||||
{
|
||||
EGLNativeDisplayType eglNativeDisplayType = NULL;
|
||||
#if (defined EGL_USE_X11)
|
||||
eglNativeDisplayType = XOpenDisplay(NULL);
|
||||
assert(eglNativeDisplayType != NULL);
|
||||
#elif EGL_API_WL
|
||||
sdisplay.display = wl_display_connect(NULL);
|
||||
sdisplay.registry = wl_display_get_registry(sdisplay.display);
|
||||
wl_registry_add_listener(sdisplay.registry,
|
||||
®istry_listener, &sdisplay);
|
||||
wl_display_dispatch(sdisplay.display);
|
||||
|
||||
return sdisplay.display;
|
||||
#elif (defined EGL_API_FB)
|
||||
eglNativeDisplayType = fbGetDisplayByIndex(0); //Pass the argument as required to show the framebuffer
|
||||
#else
|
||||
display = EGL_DEFAULT_DISPLAY;
|
||||
#endif
|
||||
return eglNativeDisplayType;
|
||||
}
|
||||
|
||||
EGLNativeWindowType fsl_createwindow(EGLDisplay egldisplay, EGLNativeDisplayType eglNativeDisplayType)
|
||||
{
|
||||
EGLNativeWindowType native_window = (EGLNativeWindowType)0;
|
||||
|
||||
#if (defined EGL_USE_X11)
|
||||
Window window, rootwindow;
|
||||
int screen = DefaultScreen(eglNativeDisplayType);
|
||||
rootwindow = RootWindow(eglNativeDisplayType,screen);
|
||||
window = XCreateSimpleWindow(eglNativeDisplayType, rootwindow, 0, 0, 400, 533, 0, 0, WhitePixel (eglNativeDisplayType, screen));
|
||||
XMapWindow(eglNativeDisplayType, window);
|
||||
native_window = window;
|
||||
#elif EGL_API_WL
|
||||
swindow.window_size.width = 800;
|
||||
swindow.window_size.height = 480;
|
||||
|
||||
swindow.display = &sdisplay;
|
||||
sdisplay.window = &swindow;
|
||||
|
||||
sdisplay.registry = wl_display_get_registry(sdisplay.display);
|
||||
wl_registry_add_listener(sdisplay.registry,
|
||||
®istry_listener, &sdisplay);
|
||||
wl_display_dispatch(sdisplay.display);
|
||||
create_wl_surface();
|
||||
|
||||
native_window = swindow.native;
|
||||
|
||||
sdisplay.cursor_surface =
|
||||
wl_compositor_create_surface(sdisplay.compositor);
|
||||
|
||||
#else
|
||||
const char *vendor = eglQueryString(egldisplay, EGL_VENDOR);
|
||||
if (strstr(vendor, "Imagination Technologies"))
|
||||
native_window = (EGLNativeWindowType)0;
|
||||
else if (strstr(vendor, "AMD"))
|
||||
native_window = (EGLNativeWindowType) open("/dev/fb0", O_RDWR);
|
||||
else if (strstr(vendor, "Vivante")) //NEEDS FIX - functs don't exist on other platforms
|
||||
{
|
||||
#if (defined EGL_API_FB)
|
||||
native_window = fbCreateWindow(eglNativeDisplayType, 0, 0, 0, 0);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown vendor [%s]\n", vendor);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return native_window;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void fsl_destroywindow(EGLNativeWindowType eglNativeWindowType, EGLNativeDisplayType eglNativeDisplayType)
|
||||
{
|
||||
(void) eglNativeWindowType;
|
||||
#if (defined EGL_USE_X11)
|
||||
//close x display
|
||||
XCloseDisplay(eglNativeDisplayType);
|
||||
#elif EGL_API_WL
|
||||
struct display * display = &sdisplay;
|
||||
struct window * window = &swindow;
|
||||
|
||||
if(eglNativeWindowType)
|
||||
{
|
||||
wl_egl_window_destroy(window->native);
|
||||
wl_shell_surface_destroy(window->shell_surface);
|
||||
wl_surface_destroy(window->surface);
|
||||
if (window->callback)
|
||||
wl_callback_destroy(window->callback);
|
||||
}
|
||||
|
||||
wl_surface_destroy(display->cursor_surface);
|
||||
|
||||
if (display->cursor_theme)
|
||||
wl_cursor_theme_destroy(display->cursor_theme);
|
||||
|
||||
if (display->shell)
|
||||
wl_shell_destroy(display->shell);
|
||||
|
||||
if (display->compositor)
|
||||
wl_compositor_destroy(display->compositor);
|
||||
|
||||
wl_display_flush(display->display);
|
||||
wl_display_disconnect(display->display);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
|
@ -0,0 +1,935 @@
|
|||
/****************************************************************************
|
||||
* Copyright (c) 2012 Freescale Semiconductor, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the Freescale Semiconductor, Inc. nor the names of
|
||||
* its contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Labels parameters
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
#define GL_FUNCS 1
|
||||
|
||||
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <FSL/fslutil.h>
|
||||
#include <math.h>
|
||||
|
||||
int LoadBMP(char *filename, Image *image)
|
||||
{
|
||||
FILE *file;
|
||||
unsigned long size; // size of the image in bytes.
|
||||
unsigned long i; // standard counter.
|
||||
unsigned short int planes; // number of planes in image (must be 1)
|
||||
unsigned short int bpp; // number of bits per pixel (must be 24)
|
||||
char temp; // temporary color storage for bgr-rgb conversion.
|
||||
|
||||
// make sure the file is there.
|
||||
if ((file = fopen(filename, "rb"))==NULL)
|
||||
{
|
||||
printf("File Not Found : %s\n",filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// seek through the bmp header, up to the width/height:
|
||||
fseek(file, 18, SEEK_CUR);
|
||||
|
||||
// read the width
|
||||
if ((i = fread(&image->sizeX, 4, 1, file)) != 1)
|
||||
{
|
||||
printf("Error reading width from %s.\n", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// read the height
|
||||
if ((i = fread(&image->sizeY, 4, 1, file)) != 1)
|
||||
{
|
||||
printf("Error reading height from %s.\n", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// calculate the size (assuming 24 bits or 3 bytes per pixel).
|
||||
size = image->sizeX * image->sizeY * 3;
|
||||
//printf("size is %lu\n",size);
|
||||
|
||||
// read the planes
|
||||
if ((fread(&planes, 2, 1, file)) != 1)
|
||||
{
|
||||
printf("Error reading planes from %s.\n", filename);
|
||||
return 0;
|
||||
}
|
||||
if (planes != 1)
|
||||
{
|
||||
printf("Planes from %s is not 1: %u\n", filename, planes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// read the bpp
|
||||
if ((i = fread(&bpp, 2, 1, file)) != 1)
|
||||
{
|
||||
printf("Error reading bpp from %s.\n", filename);
|
||||
return 0;
|
||||
}
|
||||
if (bpp != 24)
|
||||
{
|
||||
printf("Bpp from %s is not 24: %u\n", filename, bpp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// seek past the rest of the bitmap header.
|
||||
fseek(file, 24, SEEK_CUR);
|
||||
|
||||
// read the data.
|
||||
image->data = (char *) malloc(size);
|
||||
if (image->data == NULL)
|
||||
{
|
||||
printf("Error allocating memory for color-corrected image data");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((i = fread(image->data, size, 1, file)) != 1)
|
||||
{
|
||||
printf("Error reading image data from %s.\n", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i=0;i<size;i+=3)
|
||||
{ // reverse all of the colors. (bgr -> rgb)
|
||||
temp = image->data[i];
|
||||
image->data[i] = image->data[i+2];
|
||||
image->data[i+2] = temp;
|
||||
}
|
||||
|
||||
|
||||
// we're done.
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int LoadTGA(const char *textureFileName, Image *image)
|
||||
{
|
||||
FILE *f = fopen(textureFileName, "rb");
|
||||
#ifdef UNDER_CE
|
||||
if (f == NULL)
|
||||
{
|
||||
wchar_t moduleName[MAX_PATH];
|
||||
char path[MAX_PATH], * p;
|
||||
GetModuleFileName(NULL, moduleName, MAX_PATH);
|
||||
wcstombs(path, moduleName, MAX_PATH);
|
||||
p = strrchr(path, '\\');
|
||||
strcpy(p + 1, textureFileName);
|
||||
f = fopen(path, "rb");
|
||||
}
|
||||
#endif
|
||||
if(!f) return 0;
|
||||
|
||||
unsigned short width, height;
|
||||
unsigned char widthLow, widthHigh, heightLow, heightHigh;
|
||||
unsigned char headerLength = 0;
|
||||
unsigned char imageType = 0;
|
||||
unsigned char bits = 0;
|
||||
int format= 0;
|
||||
int lineWidth = 0;
|
||||
|
||||
fread(&headerLength, sizeof(unsigned char), 1, f);
|
||||
fseek(f,1,SEEK_CUR);
|
||||
fread(&imageType, sizeof(unsigned char), 1, f);
|
||||
fseek(f, 9, SEEK_CUR);
|
||||
fread(&widthLow, sizeof(unsigned char), 1, f);
|
||||
fread(&widthHigh, sizeof(unsigned char), 1, f);
|
||||
width = (widthHigh << 16) + widthLow;
|
||||
fread(&heightLow, sizeof(unsigned char), 1, f);
|
||||
fread(&heightHigh, sizeof(unsigned char), 1, f);
|
||||
height = (heightHigh << 16) + heightLow;
|
||||
fread(&bits, sizeof(unsigned char), 1, f);
|
||||
|
||||
image->sizeX = width;
|
||||
image->sizeY = height;
|
||||
|
||||
printf("width=%d height=%d\n", width, height);
|
||||
|
||||
/* Check pixel depth. */
|
||||
switch (bits)
|
||||
{
|
||||
case 16:
|
||||
/* 16-bpp RGB. */
|
||||
image->Format = GL_UNSIGNED_SHORT_5_6_5;
|
||||
break;
|
||||
|
||||
case 24:
|
||||
/* 24-bpp RGB. */
|
||||
image->Format = GL_RGB;
|
||||
break;
|
||||
|
||||
case 32:
|
||||
/* 32-bpp RGB. */
|
||||
image->Format = GL_RGBA;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Invalid pixel depth. */
|
||||
return 0;
|
||||
}
|
||||
fseek(f, headerLength + 1, SEEK_CUR);
|
||||
char *buffer = NULL;
|
||||
if(imageType != 10)
|
||||
{
|
||||
int y;
|
||||
int i;
|
||||
printf("bits=%d\n", bits);
|
||||
if((bits == 24)||(bits == 32)) //added to support for LUMINANCE and RGBA textures
|
||||
{
|
||||
format = bits >> 3;
|
||||
lineWidth = format * width;
|
||||
buffer = malloc( (bits / 8) * lineWidth * height);
|
||||
|
||||
for(y = 0; y < height; y++)
|
||||
{
|
||||
GLubyte *line = &buffer[lineWidth * y];
|
||||
fread(line, lineWidth, 1, f);
|
||||
|
||||
if(format!= 1)
|
||||
{
|
||||
for(i=0;i<lineWidth ; i+=format) //swap R and B because TGA are stored in BGR format
|
||||
{
|
||||
int temp = line[i];
|
||||
line[i] = line[i+2];
|
||||
line[i+2] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose(f);
|
||||
image->data = buffer;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
image->data = buffer;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Name: fslLoadCTES
|
||||
// Desc: Helper function to load an compressed image file (ATC, ETC, etc.) from the compressenator
|
||||
// At exit nFormat contains the GL
|
||||
//--------------------------------------------------------------------------------------
|
||||
char* fslLoadCTES( char* strFileName, unsigned int* pWidth, unsigned int* pHeight,
|
||||
unsigned int* nFormat, unsigned int* nSize )
|
||||
{
|
||||
unsigned int nTotalBlocks, nBytesPerBlock, nHasAlpha;
|
||||
char* pBits8;
|
||||
|
||||
struct CTES_HEADER
|
||||
{
|
||||
unsigned int signature;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
unsigned int flags;
|
||||
unsigned int dataOffset; // From start of header/file
|
||||
} header;
|
||||
|
||||
// Read the file
|
||||
FILE* file = fopen( strFileName, "rb" );
|
||||
if( NULL == file )
|
||||
{
|
||||
printf("Error loading file: %s \n",strFileName);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (fread( &header, sizeof(header), 1, file ) != 1)
|
||||
{
|
||||
printf("Error loading file : %s \n",strFileName);
|
||||
fclose( file );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nTotalBlocks = ((header.width + 3) >> 2) * ((header.height + 3) >> 2);
|
||||
nHasAlpha = header.flags & ATC_RGBA;
|
||||
nBytesPerBlock = (nHasAlpha) ? 16 : 8;
|
||||
|
||||
(*nSize) = nTotalBlocks * nBytesPerBlock;
|
||||
(*pWidth) = header.width;
|
||||
(*pHeight) = header.height;
|
||||
|
||||
switch (header.signature)
|
||||
{
|
||||
case ATC_SIGNATURE:
|
||||
if(nHasAlpha && (header.flags & ATC_ALPHA_INTERPOLATED))
|
||||
(*nFormat) = GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD;
|
||||
else if(nHasAlpha)
|
||||
(*nFormat) = GL_ATC_RGBA_EXPLICIT_ALPHA_AMD;
|
||||
else
|
||||
(*nFormat) = GL_ATC_RGB_AMD;
|
||||
break;
|
||||
case ATI1N_SIGNATURE:
|
||||
(*nFormat) = GL_3DC_X_AMD;
|
||||
break;
|
||||
case ATI2N_SIGNATURE:
|
||||
(*nFormat) = GL_3DC_XY_AMD;
|
||||
break;
|
||||
case ETC_SIGNATURE:
|
||||
if(nHasAlpha)
|
||||
{
|
||||
printf("Unsupported texture format\n");
|
||||
return NULL;
|
||||
}
|
||||
(*nFormat) = GL_ETC1_RGB8_OES;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Unsupported texture format\n");
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
pBits8 = (char*)malloc(sizeof(char) * (*nSize));
|
||||
|
||||
// Read the encoded image
|
||||
fseek(file, header.dataOffset, SEEK_SET);
|
||||
if (fread(pBits8, *nSize, 1, file) != 1) {
|
||||
printf("Error loading file : %s \n",strFileName);
|
||||
fclose( file );
|
||||
free( pBits8 );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fclose( file );
|
||||
|
||||
return pBits8;
|
||||
}
|
||||
|
||||
fslBool fslUnProject(float winx,float winy, float winz, float modelMatrix[16], float projMatrix[16], int viewport[4], float *objx, float *objy, float *objz)
|
||||
{
|
||||
float finalMatrix[16];
|
||||
float finalMatrixTmp[16];
|
||||
float in[4];
|
||||
float out[4];
|
||||
|
||||
fslMultMatrix4x4(finalMatrixTmp,modelMatrix,projMatrix);
|
||||
|
||||
if(!fslInvertMatrix4x4( finalMatrixTmp, finalMatrix))
|
||||
{
|
||||
printf("error inverting matrix \n");
|
||||
return FSL_FALSE;
|
||||
}
|
||||
|
||||
in[0]=winx;
|
||||
in[1]=winy;
|
||||
in[2]=winz;
|
||||
in[3]=1.0;
|
||||
//map x and y from coordinates
|
||||
in[0]=(in[0]-viewport[0])/ viewport[2];
|
||||
in[1]=(in[1]-viewport[1])/ viewport[3];
|
||||
|
||||
//map range to -1 to 1
|
||||
in[0]= in[0]*2-1;
|
||||
in[1]= in[1]*2-1;
|
||||
in[2]= in[2]*2-1;
|
||||
//printf("in: %f %f %f \n",in[0],in[1],in[2]);
|
||||
fslMultMatrix4x4Vec4x1 ( finalMatrix, in, out );
|
||||
|
||||
|
||||
if(out[3]== 0.0)
|
||||
return FSL_FALSE;
|
||||
|
||||
|
||||
out[0] /=out[3];
|
||||
out[1] /=out[3];
|
||||
out[2] /=out[3];
|
||||
|
||||
|
||||
*objx = out[0];
|
||||
*objy = out[1];
|
||||
*objz = out[2];
|
||||
|
||||
return FSL_TRUE;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Name: fslEGLCheck
|
||||
// Desc: Helper function to print EGL errors and exits application
|
||||
//--------------------------------------------------------------------------------------
|
||||
fslBool fslEGLCheck( fslBool bExitOnFailure)
|
||||
{
|
||||
EGLint eglerr = eglGetError();
|
||||
|
||||
if(eglerr != EGL_SUCCESS)
|
||||
{
|
||||
switch(eglerr){
|
||||
case EGL_NOT_INITIALIZED:
|
||||
fprintf(stdout, "EGL Fail = EGL_NOT_INITIALIZED (0x%x) \n", eglerr);
|
||||
break;
|
||||
case EGL_BAD_ACCESS:
|
||||
fprintf(stdout, "EGL Fail = EGL_BAD_ACCESS (0x%x) \n", eglerr);
|
||||
break;
|
||||
case EGL_BAD_ALLOC:
|
||||
fprintf(stdout, "EGL Fail = EGL_BAD_ALLOC (0x%x) \n", eglerr);
|
||||
break;
|
||||
case EGL_BAD_ATTRIBUTE:
|
||||
fprintf(stdout, "EGL Fail = EGL_BAD_ATTRIBUTE(0x%x) \n", eglerr);
|
||||
break;
|
||||
case EGL_BAD_CONFIG:
|
||||
fprintf(stdout, "EGL Fail = EGL_BAD_CONFIG (0x%x) \n", eglerr);
|
||||
break;
|
||||
case EGL_BAD_CONTEXT:
|
||||
fprintf(stdout, "EGL Fail = EGL_BAD_CONTEXT (0x%x) \n", eglerr);
|
||||
break;
|
||||
case EGL_BAD_CURRENT_SURFACE:
|
||||
fprintf(stdout, "EGL Fail = EGL_BAD_CURRENT_SURFACE (0x%x) \n", eglerr);
|
||||
break;
|
||||
case EGL_BAD_DISPLAY:
|
||||
fprintf(stdout, "EGL Fail = EGL_BAD_DISPLAY (0x%x) \n", eglerr);
|
||||
break;
|
||||
case EGL_BAD_MATCH:
|
||||
fprintf(stdout, "EGL Fail = EGL_BAD_MATCH (0x%x) \n", eglerr);
|
||||
break;
|
||||
case EGL_BAD_NATIVE_PIXMAP:
|
||||
fprintf(stdout, "EGL Fail = EGL_BAD_NATIVE_PIXMAP (0x%x) \n", eglerr);
|
||||
break;
|
||||
case EGL_BAD_NATIVE_WINDOW:
|
||||
fprintf(stdout, "EGL Fail = EGL_BAD_NATIVE_WINDOW (0x%x) \n", eglerr);
|
||||
break;
|
||||
case EGL_BAD_PARAMETER:
|
||||
fprintf(stdout, "EGL Fail = EGL_BAD_PARAMETER (0x%x) \n", eglerr);
|
||||
break;
|
||||
case EGL_BAD_SURFACE:
|
||||
fprintf(stdout, "EGL Fail = EGL_BAD_SURFACE (0x%x) \n", eglerr);
|
||||
break;
|
||||
case EGL_CONTEXT_LOST:
|
||||
fprintf(stdout, "EGL Fail = EGL_CONTEXT_LOST (0x%x) \n", eglerr);
|
||||
break;
|
||||
default:
|
||||
fprintf(stdout, "EGL Fail = 0x%x \n", eglerr);
|
||||
}
|
||||
|
||||
if (bExitOnFailure)
|
||||
exit(EXIT_FAILURE);
|
||||
else
|
||||
return FSL_FALSE;
|
||||
}
|
||||
|
||||
return FSL_TRUE;
|
||||
}
|
||||
|
||||
#ifdef GL_FUNCS
|
||||
fslBool fslInit2DBMPTextureGL(char* strFileName, GLuint *pTextureHandle){
|
||||
|
||||
Image *image1;
|
||||
|
||||
// allocate space for texture we will use
|
||||
image1 = (Image *) malloc(sizeof(Image));
|
||||
if (image1 == NULL) {
|
||||
printf("Error allocating space for image");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!LoadBMP(strFileName, image1)) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
glGenTextures( 1, pTextureHandle );
|
||||
glBindTexture( GL_TEXTURE_2D, *pTextureHandle );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
|
||||
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,image1->sizeX,image1->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,image1->data);
|
||||
free(image1);
|
||||
return FSL_TRUE;
|
||||
|
||||
}
|
||||
|
||||
|
||||
fslBool fslInit2DTGATextureGL(char* strFileName, unsigned int *pTextureHandle){
|
||||
|
||||
Image *image1;
|
||||
|
||||
// allocate space for texture we will use
|
||||
image1 = (Image *) malloc(sizeof(Image));
|
||||
if (image1 == NULL) {
|
||||
printf("Error allocating space for image");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!LoadTGA(strFileName, image1)) {
|
||||
printf("Error loading TGA\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
glGenTextures( 1, pTextureHandle );
|
||||
glBindTexture( GL_TEXTURE_2D, *pTextureHandle );
|
||||
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
|
||||
/* Set unpack alignment. */
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexImage2D(GL_TEXTURE_2D,0 , image1->Format, image1->sizeX,image1->sizeY,0,image1->Format,GL_UNSIGNED_BYTE,image1->data);
|
||||
free(image1->data);
|
||||
free(image1);
|
||||
return FSL_TRUE;
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Name: fslInit2DCTESTextureGL
|
||||
// Desc: Helper function to load a CTES texture file and bind it to a given GL texture handle
|
||||
//--------------------------------------------------------------------------------------
|
||||
fslBool fslInit2DCTESTextureGL( char* strFileName, GLuint *pTextureHandle )
|
||||
{
|
||||
unsigned int nWidth, nHeight, nFormat, nSize;
|
||||
char* pImageData = fslLoadCTES( strFileName, &nWidth, &nHeight, &nFormat, &nSize );
|
||||
|
||||
if( NULL == pImageData )
|
||||
{
|
||||
printf("Error loading texture! \n");
|
||||
return FSL_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Texture [%s] succesully read (%d x %d , %d) \n",strFileName,nWidth,nHeight,nSize);
|
||||
}
|
||||
|
||||
glGenTextures( 1, pTextureHandle );
|
||||
glBindTexture( GL_TEXTURE_2D, *pTextureHandle );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
|
||||
glCompressedTexImage2D( GL_TEXTURE_2D, 0, nFormat, nWidth, nHeight, 0, nSize, pImageData );
|
||||
free(pImageData);
|
||||
|
||||
return FSL_TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FSL_EGL_USE_X11
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Name: fslLoadFontX
|
||||
// Desc: Helper function to load a X11 font into given struct
|
||||
//--------------------------------------------------------------------------------------
|
||||
void fslLoadFontX(Display *display, XFontStruct **font_info)
|
||||
{
|
||||
char *fontname = "9x15";
|
||||
|
||||
if ((*font_info=XLoadQueryFont(display,fontname)) == NULL)
|
||||
{
|
||||
printf("stderr, basicwin: cannot open 9x15 font\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Name: fslErrorHandlerX
|
||||
// Desc: Helper function to print incoming X11 server errors
|
||||
//--------------------------------------------------------------------------------------
|
||||
int fslErrorHandlerX( Display *display, XErrorEvent *error )
|
||||
{
|
||||
char errorText[1024];
|
||||
XGetErrorText( display, error->error_code, errorText, sizeof(errorText) );
|
||||
printf( "\t --- X Error: %s ---\n", errorText );
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Name: fslGetTickCount
|
||||
// Desc: Helper function to get current time
|
||||
//--------------------------------------------------------------------------------------
|
||||
unsigned int fslGetTickCount()
|
||||
{
|
||||
struct timeval tv;
|
||||
if(gettimeofday(&tv, NULL) != 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Name: fslMulMatrix4x4
|
||||
// Desc: 4x4 Matix Muliply
|
||||
//--------------------------------------------------------------------------------------
|
||||
void fslMultMatrix4x4( float *matC, float *matA, float *matB)
|
||||
{
|
||||
matC[ 0] = matA[ 0] * matB[ 0] + matA[ 1] * matB[ 4] + matA[ 2] * matB[ 8] + matA[ 3] * matB[12];
|
||||
matC[ 1] = matA[ 0] * matB[ 1] + matA[ 1] * matB[ 5] + matA[ 2] * matB[ 9] + matA[ 3] * matB[13];
|
||||
matC[ 2] = matA[ 0] * matB[ 2] + matA[ 1] * matB[ 6] + matA[ 2] * matB[10] + matA[ 3] * matB[14];
|
||||
matC[ 3] = matA[ 0] * matB[ 3] + matA[ 1] * matB[ 7] + matA[ 2] * matB[11] + matA[ 3] * matB[15];
|
||||
matC[ 4] = matA[ 4] * matB[ 0] + matA[ 5] * matB[ 4] + matA[ 6] * matB[ 8] + matA[ 7] * matB[12];
|
||||
matC[ 5] = matA[ 4] * matB[ 1] + matA[ 5] * matB[ 5] + matA[ 6] * matB[ 9] + matA[ 7] * matB[13];
|
||||
matC[ 6] = matA[ 4] * matB[ 2] + matA[ 5] * matB[ 6] + matA[ 6] * matB[10] + matA[ 7] * matB[14];
|
||||
matC[ 7] = matA[ 4] * matB[ 3] + matA[ 5] * matB[ 7] + matA[ 6] * matB[11] + matA[ 7] * matB[15];
|
||||
matC[ 8] = matA[ 8] * matB[ 0] + matA[ 9] * matB[ 4] + matA[10] * matB[ 8] + matA[11] * matB[12];
|
||||
matC[ 9] = matA[ 8] * matB[ 1] + matA[ 9] * matB[ 5] + matA[10] * matB[ 9] + matA[11] * matB[13];
|
||||
matC[10] = matA[ 8] * matB[ 2] + matA[ 9] * matB[ 6] + matA[10] * matB[10] + matA[11] * matB[14];
|
||||
matC[11] = matA[ 8] * matB[ 3] + matA[ 9] * matB[ 7] + matA[10] * matB[11] + matA[11] * matB[15];
|
||||
matC[12] = matA[12] * matB[ 0] + matA[13] * matB[ 4] + matA[14] * matB[ 8] + matA[15] * matB[12];
|
||||
matC[13] = matA[12] * matB[ 1] + matA[13] * matB[ 5] + matA[14] * matB[ 9] + matA[15] * matB[13];
|
||||
matC[14] = matA[12] * matB[ 2] + matA[13] * matB[ 6] + matA[14] * matB[10] + matA[15] * matB[14];
|
||||
matC[15] = matA[12] * matB[ 3] + matA[13] * matB[ 7] + matA[14] * matB[11] + matA[15] * matB[15];
|
||||
}
|
||||
|
||||
fslBool fslInvertMatrix4x4( float *src, float *inverse)
|
||||
{
|
||||
int i, j, k, swap;
|
||||
double t;
|
||||
double temp[4][4];
|
||||
|
||||
for (i=0; i<4; i++) {
|
||||
for (j=0; j<4; j++) {
|
||||
temp[i][j] = src[i*4+j];
|
||||
}
|
||||
}
|
||||
|
||||
inverse[ 0] = 1.0f;
|
||||
inverse[ 1] = 0.0f;
|
||||
inverse[ 2] = 0.0f;
|
||||
inverse[ 3] = 0.0f;
|
||||
inverse[ 4] = 0.0f;
|
||||
inverse[ 5] = 1.0f;
|
||||
inverse[ 6] = 0.0f;
|
||||
inverse[ 7] = 0.0f;
|
||||
inverse[ 8] = 0.0f;
|
||||
inverse[ 9] = 0.0f;
|
||||
inverse[10] = 1.0f;
|
||||
inverse[11] = 0.0f;
|
||||
inverse[12] = 0.0f;
|
||||
inverse[13] = 0.0f;
|
||||
inverse[14] = 0.0f;
|
||||
inverse[15] = 1.0f;
|
||||
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
/*
|
||||
** Look for largest element in column
|
||||
*/
|
||||
swap = i;
|
||||
for (j = i + 1; j < 4; j++) {
|
||||
if (fabs(temp[j][i]) > fabs(temp[i][i])) {
|
||||
swap = j;
|
||||
}
|
||||
}
|
||||
|
||||
if (swap != i) {
|
||||
/*
|
||||
** Swap rows.
|
||||
*/
|
||||
for (k = 0; k < 4; k++) {
|
||||
t = temp[i][k];
|
||||
temp[i][k] = temp[swap][k];
|
||||
temp[swap][k] = t;
|
||||
|
||||
t = inverse[i*4+k];
|
||||
inverse[i*4+k] = inverse[swap*4+k];
|
||||
inverse[swap*4+k] = t;
|
||||
}
|
||||
}
|
||||
|
||||
if (temp[i][i] == 0) {
|
||||
/*
|
||||
** No non-zero pivot. The matrix is singular, which shouldn't
|
||||
** happen. This means the user gave us a bad matrix.
|
||||
*/
|
||||
return FSL_FALSE;
|
||||
}
|
||||
|
||||
t = temp[i][i];
|
||||
for (k = 0; k < 4; k++) {
|
||||
temp[i][k] /= t;
|
||||
inverse[i*4+k] /= t;
|
||||
}
|
||||
for (j = 0; j < 4; j++) {
|
||||
if (j != i) {
|
||||
t = temp[j][i];
|
||||
for (k = 0; k < 4; k++) {
|
||||
temp[j][k] -= temp[i][k]*t;
|
||||
inverse[j*4+k] -= inverse[i*4+k]*t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return FSL_TRUE;
|
||||
}
|
||||
|
||||
void fslPerspectiveMatrix4x4 ( float *m, float fov, float aspect, float zNear, float zFar)
|
||||
{
|
||||
const float h = 1.0f/tan(fov*PI_OVER_360);
|
||||
float neg_depth = zNear-zFar;
|
||||
|
||||
m[0] = h / aspect;
|
||||
m[1] = 0;
|
||||
m[2] = 0;
|
||||
m[3] = 0;
|
||||
|
||||
m[4] = 0;
|
||||
m[5] = h;
|
||||
m[6] = 0;
|
||||
m[7] = 0;
|
||||
|
||||
m[8] = 0;
|
||||
m[9] = 0;
|
||||
m[10] = (zFar + zNear)/neg_depth;
|
||||
m[11] = -1;
|
||||
|
||||
m[12] = 0;
|
||||
m[13] = 0;
|
||||
m[14] = 2.0f*(zNear*zFar)/neg_depth;
|
||||
m[15] = 0;
|
||||
|
||||
}
|
||||
|
||||
void fslMultMatrix4x4Vec4x1 ( float *matA, float *vecA, float *vecB )
|
||||
{
|
||||
int i;
|
||||
|
||||
for ( i = 0; i < 4; i++ )
|
||||
{
|
||||
vecB[i] = vecA[0] * matA[0*4+i] + vecA[1] * matA[1*4+i] + vecA[2] * matA[2*4+i] + vecA[3] * matA[3*4+i];
|
||||
}
|
||||
}
|
||||
|
||||
void fslRotateMatrix4x4 (float *m, float angle, fslAxis axis)
|
||||
{
|
||||
float radians = PI_OVER_360*2*angle;
|
||||
float rotate[16] = {0};
|
||||
|
||||
fslLoadIdentityMatrix4x4(rotate);
|
||||
|
||||
switch (axis)
|
||||
{
|
||||
case FSL_X_AXIS:
|
||||
rotate[5] = cos(radians);
|
||||
rotate[6] = sin(radians);
|
||||
rotate[9] = -sin(radians);
|
||||
rotate[10] = cos(radians);
|
||||
fslMultMatrix4x4(m, rotate, m);
|
||||
break;
|
||||
case FSL_Y_AXIS:
|
||||
rotate[0] = cos(radians);
|
||||
rotate[2] = -sin(radians);
|
||||
rotate[8] = sin(radians);
|
||||
rotate[10] = cos(radians);
|
||||
fslMultMatrix4x4(m, rotate, m);
|
||||
break;
|
||||
case FSL_Z_AXIS:
|
||||
rotate[0] = cos(radians);
|
||||
rotate[1] = sin(radians);
|
||||
rotate[4] = -sin(radians);
|
||||
rotate[5] = cos(radians);
|
||||
fslMultMatrix4x4(m, rotate, m);
|
||||
break;
|
||||
default:
|
||||
printf("invalid axis \n");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void fslTranslateMatrix4x4 (float *m, float transX, float transY, float transZ)
|
||||
{
|
||||
float trans[16] = {0};
|
||||
fslLoadIdentityMatrix4x4(trans);
|
||||
|
||||
trans[12]=transX;
|
||||
trans[13]=transY;
|
||||
trans[14]=transZ;
|
||||
|
||||
fslMultMatrix4x4(m, trans, m);
|
||||
}
|
||||
|
||||
void fslScaleMatrix4x4 (float *m, float scaleX, float scaleY, float scaleZ)
|
||||
{
|
||||
float scale[16] = {0};
|
||||
fslLoadIdentityMatrix4x4(scale);
|
||||
|
||||
scale[0]=scaleX;
|
||||
scale[5]=scaleY;
|
||||
scale[10]=scaleZ;
|
||||
|
||||
fslMultMatrix4x4(m, scale, m);
|
||||
}
|
||||
|
||||
void fslLoadIdentityMatrix4x4 (float *m)
|
||||
{
|
||||
m[0] = 1;
|
||||
m[1] = 0;
|
||||
m[2] = 0;
|
||||
m[3] = 0;
|
||||
|
||||
m[4] = 0;
|
||||
m[5] = 1;
|
||||
m[6] = 0;
|
||||
m[7] = 0;
|
||||
|
||||
m[8] = 0;
|
||||
m[9] = 0;
|
||||
m[10] = 1;
|
||||
m[11] = 0;
|
||||
|
||||
m[12] = 0;
|
||||
m[13] = 0;
|
||||
m[14] = 0;
|
||||
m[15] = 1;
|
||||
}
|
||||
|
||||
float fslInnerProduct( float *v, float *q)
|
||||
{
|
||||
return v[0]*q[0]+v[1]*q[1]+v[2]*q[2];
|
||||
}
|
||||
//result = endpoint-startPoint
|
||||
void fslDirectionVector(float *result, float *endPoint, float *startPoint)
|
||||
{
|
||||
result[0]= endPoint[0]-startPoint[0];
|
||||
result[1]= endPoint[1]-startPoint[1];
|
||||
result[2]= endPoint[2]-startPoint[2];
|
||||
}
|
||||
//a = crossProduct(b,c)
|
||||
void fslCrossProduct(float *result, float *b, float* c)
|
||||
{
|
||||
result[0]= b[1]*c[2]-c[1]*b[2];
|
||||
result[1]= b[2]*c[0]-c[2]*b[0];
|
||||
result[2]= b[0]*c[1]-c[0]*b[1];
|
||||
}
|
||||
//p is the startpoint, d is the direction vector, v0,v1,v2 represent the triangle
|
||||
int fslRayIntersectsTriangle(float *p, float *d,float *v0, float *v1, float *v2)
|
||||
{
|
||||
float e1[3]={0.0, 0.0, 0.0};
|
||||
float e2[3]={0.0, 0.0, 0.0};
|
||||
float h[3] = {0.0, 0.0, 0.0};
|
||||
float s[3] = {0.0, 0.0, 0.0};
|
||||
float q[3] = {0.0, 0.0, 0.0};
|
||||
float a,f,u,v,t;
|
||||
fslDirectionVector(e1,v1,v0);
|
||||
fslDirectionVector(e2,v2,v0);
|
||||
fslCrossProduct(h,d,e2);
|
||||
//get the inner product
|
||||
a=fslInnerProduct(e1,h);
|
||||
if(a>-0.00001&& a<0.00001)
|
||||
return 0;
|
||||
f= 1/a;
|
||||
fslDirectionVector(s,p,v0);
|
||||
u=f*(fslInnerProduct(s,h));
|
||||
|
||||
if(u<0.0 || u>1.0)
|
||||
return 0;
|
||||
|
||||
fslCrossProduct(q,s,e1);
|
||||
v = f*fslInnerProduct(d,q);
|
||||
if(v< 0.0 || u+v > 1.0)
|
||||
return 0;
|
||||
//we can compute t to find out where the intersection point is on the line
|
||||
t= f*fslInnerProduct(e2,q);
|
||||
if(t > 0.00001) //ray intersection
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
void fslNormalize(float *v)
|
||||
{
|
||||
float mag =v[0]*v[0]+v[1]*v[1]+v[2]*v[2];
|
||||
sqrt(mag);
|
||||
v[0]=v[0]/mag;
|
||||
v[1]=v[1]/mag;
|
||||
v[2]=v[2]/mag;
|
||||
//printf("vector Normalized is %f,%f,%f\n",v[0],v[1],v[2]);
|
||||
}
|
||||
void fslPrintMatrix4x4(float *m){
|
||||
|
||||
printf(" %f %f %f %f \n", m[0], m[1], m[2], m[3]);
|
||||
printf(" %f %f %f %f \n", m[4], m[5], m[6], m[7]);
|
||||
printf(" %f %f %f %f \n", m[8], m[9], m[10], m[11]);
|
||||
printf(" %f %f %f %f \n", m[12], m[13], m[14], m[15]);
|
||||
|
||||
}
|
||||
void fslCalculateNormals(float *triangleArray, int size, float *normalArray)
|
||||
{
|
||||
printf("enter fslCalculateNormals \n");
|
||||
|
||||
|
||||
int index =0;
|
||||
|
||||
int i=0;
|
||||
for(i=0; i< size/3; i++){
|
||||
|
||||
float v1[3]={0.0f};
|
||||
float v2[3]={0.0f};
|
||||
float v3[3]={0.0f};
|
||||
//float v4[3]={0.0f};
|
||||
|
||||
float A[3]={0.0f};
|
||||
float B[3]={0.0f};
|
||||
/*float C[3]={0.0f};
|
||||
float D[3]={0.0f};*/
|
||||
|
||||
v1[0]=triangleArray[9*i];//9 is for 9 values (3 vertices) used per loop
|
||||
v1[1]=triangleArray[9*i+1];
|
||||
v1[2]=triangleArray[12*i+2];
|
||||
|
||||
v2[0]=triangleArray[9*i+3];
|
||||
v2[1]=triangleArray[9*i+4];
|
||||
v2[2]=triangleArray[9*i+5];
|
||||
|
||||
v3[0]=triangleArray[9*i+6];
|
||||
v3[1]=triangleArray[9*i+7];
|
||||
v3[2]=triangleArray[9*i+8];
|
||||
|
||||
|
||||
A[0]=v1[0]-v2[0];
|
||||
A[1]=v1[1]-v2[1];
|
||||
A[2]=v1[2]-v2[2];
|
||||
|
||||
B[0]=v2[0]-v3[0];
|
||||
B[1]=v2[1]-v3[1];
|
||||
B[2]=v2[2]-v3[2];
|
||||
float result[3]={0.0f};
|
||||
|
||||
printf("adding normal %i\n",index);
|
||||
fslCrossProduct(result, A, B);
|
||||
fslNormalize(result);
|
||||
normalArray[3*i]=result[0];
|
||||
normalArray[3*i+1]=result[1];
|
||||
normalArray[3*i+2]=result[2];
|
||||
|
||||
printf("adding normal: %f %f %f \n",result[0],result[1],result[2]);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,334 @@
|
|||
/*
|
||||
* Copyright © 2009 Ian D. Romanick
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include <GLU3/glu3.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
#define DEG2RAD(d) ((d) * M_PI / 180.0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
const GLUmat4 gluIdentityMatrix ( { 1.0f, 0.0f, 0.0f, 0.0f } , { 0.0f, 1.0f, 0.0f, 0.0f } , { 0.0f, 0.0f, 1.0f, 0.0f } , { 0.0f, 0.0f, 0.0f, 1.0f } );
|
||||
#else
|
||||
const GLUmat4 gluIdentityMatrix = {
|
||||
{
|
||||
{ { 1.0f, 0.0f, 0.0f, 0.0f } },
|
||||
{ { 0.0f, 1.0f, 0.0f, 0.0f } },
|
||||
{ { 0.0f, 0.0f, 1.0f, 0.0f } },
|
||||
{ { 0.0f, 0.0f, 0.0f, 1.0f } }
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
void gluTranslate4v(GLUmat4 *result, const GLUvec4 *t)
|
||||
{
|
||||
memcpy(result, & gluIdentityMatrix, sizeof(gluIdentityMatrix));
|
||||
result->col[3] = *t;
|
||||
result->col[3].values[3] = 1.0f;
|
||||
}
|
||||
|
||||
|
||||
void gluScale4v(GLUmat4 *result, const GLUvec4 *t)
|
||||
{
|
||||
memcpy(result, & gluIdentityMatrix, sizeof(gluIdentityMatrix));
|
||||
result->col[0].values[0] = t->values[0];
|
||||
result->col[1].values[1] = t->values[1];
|
||||
result->col[2].values[2] = t->values[2];
|
||||
}
|
||||
|
||||
void gluLookAt4v(GLUmat4 *result, const GLUvec4 *_eye, const GLUvec4 *_center, const GLUvec4 *_up)
|
||||
{
|
||||
#ifdef __cplusplus
|
||||
static const GLUvec4 col3( 0.0f, 0.0f, 0.0f, 1.0f );
|
||||
const GLUvec4 e( -_eye->values[0], -_eye->values[1], -_eye->values[2], 0.0f );
|
||||
#else
|
||||
static const GLUvec4 col3 = { { 0.0f, 0.0f, 0.0f, 1.0f } };
|
||||
const GLUvec4 e = {
|
||||
{ -_eye->values[0], -_eye->values[1], -_eye->values[2], 0.0f }
|
||||
};
|
||||
|
||||
#endif
|
||||
GLUmat4 translate;
|
||||
GLUmat4 rotate;
|
||||
GLUmat4 rotateT;
|
||||
GLUvec4 f;
|
||||
GLUvec4 s;
|
||||
GLUvec4 u;
|
||||
GLUvec4 center, up;
|
||||
|
||||
center = *_center;
|
||||
center.values[3] = 0;
|
||||
up = *_up;
|
||||
up.values[3] = 0;
|
||||
|
||||
gluAdd4v_4v(& f, ¢er, &e);
|
||||
gluNormalize4v(& f, & f);
|
||||
|
||||
gluNormalize4v(& u, &up);
|
||||
|
||||
gluCross4v(& s, & f, & u);
|
||||
gluCross4v(& u, & s, & f);
|
||||
|
||||
rotate.col[0] = s;
|
||||
rotate.col[1] = u;
|
||||
rotate.col[2].values[0] = -f.values[0];
|
||||
rotate.col[2].values[1] = -f.values[1];
|
||||
rotate.col[2].values[2] = -f.values[2];
|
||||
rotate.col[2].values[3] = 0.0f;
|
||||
rotate.col[3] = col3;
|
||||
gluTranspose4m(& rotateT, & rotate);
|
||||
|
||||
gluTranslate4v(& translate, & e);
|
||||
gluMult4m_4m(result, & rotateT, & translate);
|
||||
}
|
||||
|
||||
void gluRotate4v(GLUmat4 *result, const GLUvec4 *_axis, GLfloat angle)
|
||||
{
|
||||
GLUvec4 axis;
|
||||
const float c = cos(angle);
|
||||
const float s = sin(angle);
|
||||
const float one_c = 1.0 - c;
|
||||
|
||||
float xx;
|
||||
float yy;
|
||||
float zz;
|
||||
|
||||
float xs;
|
||||
float ys;
|
||||
float zs;
|
||||
|
||||
float xy;
|
||||
float xz;
|
||||
float yz;
|
||||
|
||||
|
||||
gluNormalize4v(& axis, _axis);
|
||||
|
||||
xx = axis.values[0] * axis.values[0];
|
||||
yy = axis.values[1] * axis.values[1];
|
||||
zz = axis.values[2] * axis.values[2];
|
||||
|
||||
xs = axis.values[0] * s;
|
||||
ys = axis.values[1] * s;
|
||||
zs = axis.values[2] * s;
|
||||
|
||||
xy = axis.values[0] * axis.values[1];
|
||||
xz = axis.values[0] * axis.values[2];
|
||||
yz = axis.values[1] * axis.values[2];
|
||||
|
||||
|
||||
result->col[0].values[0] = (one_c * xx) + c;
|
||||
result->col[0].values[1] = (one_c * xy) + zs;
|
||||
result->col[0].values[2] = (one_c * xz) - ys;
|
||||
result->col[0].values[3] = 0.0;
|
||||
|
||||
result->col[1].values[0] = (one_c * xy) - zs;
|
||||
result->col[1].values[1] = (one_c * yy) + c;
|
||||
result->col[1].values[2] = (one_c * yz) + xs;
|
||||
result->col[1].values[3] = 0.0;
|
||||
|
||||
|
||||
result->col[2].values[0] = (one_c * xz) + ys;
|
||||
result->col[2].values[1] = (one_c * yz) - xs;
|
||||
result->col[2].values[2] = (one_c * zz) + c;
|
||||
result->col[2].values[3] = 0.0;
|
||||
|
||||
result->col[3].values[0] = 0.0;
|
||||
result->col[3].values[1] = 0.0;
|
||||
result->col[3].values[2] = 0.0;
|
||||
result->col[3].values[3] = 1.0;
|
||||
}
|
||||
|
||||
void gluFrustum6f(GLUmat4 *result,
|
||||
GLfloat left, GLfloat right, GLfloat bottom, GLfloat top,
|
||||
GLfloat n, GLfloat f)
|
||||
{
|
||||
if ((right == left) || (top == bottom) || (n == f)
|
||||
|| (n < 0.0) || (f < 0.0))
|
||||
return;
|
||||
|
||||
|
||||
memcpy(result, &gluIdentityMatrix, sizeof(gluIdentityMatrix));
|
||||
|
||||
result->col[0].values[0] = (2.0 * n) / (right - left);
|
||||
result->col[1].values[1] = (2.0 * n) / (top - bottom);
|
||||
|
||||
result->col[2].values[0] = (right + left) / (right - left);
|
||||
result->col[2].values[1] = (top + bottom) / (top - bottom);
|
||||
result->col[2].values[2] = -(f + n) / (f - n);
|
||||
result->col[2].values[3] = -1.0;
|
||||
|
||||
result->col[3].values[2] = -(2.0 * f * n) / (f - n);
|
||||
result->col[3].values[3] = 0.0;
|
||||
}
|
||||
|
||||
void gluPerspective4f(GLUmat4 *result,
|
||||
GLfloat fovy, GLfloat aspect, GLfloat n, GLfloat f)
|
||||
{
|
||||
const double sine = sin(DEG2RAD(fovy / 2.0));
|
||||
const double cosine = cos(DEG2RAD(fovy / 2.0));
|
||||
const double sine_aspect = sine * aspect;
|
||||
const double dz = f - n;
|
||||
|
||||
|
||||
memcpy(result, &gluIdentityMatrix, sizeof(gluIdentityMatrix));
|
||||
if ((sine == 0.0) || (dz == 0.0) || (sine_aspect == 0.0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
result->col[0].values[0] = cosine / sine_aspect;
|
||||
result->col[1].values[1] = cosine / sine;
|
||||
result->col[2].values[2] = -(f + n) / dz;
|
||||
result->col[2].values[3] = -1.0;
|
||||
result->col[3].values[2] = -2.0 * n * f / dz;
|
||||
result->col[3].values[3] = 0.0;
|
||||
}
|
||||
|
||||
void gluOrtho6f(GLUmat4 *result,
|
||||
GLfloat left, GLfloat right, GLfloat bottom, GLfloat top,
|
||||
GLfloat n, GLfloat f)
|
||||
{
|
||||
if ((right == left) || (top == bottom) || (n == f))
|
||||
return;
|
||||
|
||||
(void) memcpy(result, & gluIdentityMatrix, sizeof(*result));
|
||||
result->col[0].values[0] = 2.0 / (right - left);
|
||||
result->col[1].values[1] = 2.0 / (top - bottom);
|
||||
result->col[2].values[2] = -2.0 / (f - n);
|
||||
|
||||
result->col[3].values[0] = -(right + left) / (right - left);
|
||||
result->col[3].values[1] = -(top + bottom) / (top - bottom);
|
||||
result->col[3].values[2] = -(f + n) / (f - n);
|
||||
}
|
||||
|
||||
void gluOrtho4f(GLUmat4 *result, GLfloat left, GLfloat right, GLfloat bottom,
|
||||
GLfloat top)
|
||||
{
|
||||
gluOrtho6f(result, left, right, bottom, top, -1.0, 1.0);
|
||||
}
|
||||
|
||||
|
||||
static double det3(const GLUmat4 *m, unsigned i, unsigned j)
|
||||
{
|
||||
unsigned r;
|
||||
unsigned c;
|
||||
double det = 0.0;
|
||||
GLUvec4 col[6];
|
||||
|
||||
|
||||
/* Generate a 3x3 matrix from the original matrix with the ith column
|
||||
* and the jth row removed. The columns of the matrix are duplicated
|
||||
* to make the 'c - r' column addressing, below, work out easier.
|
||||
*/
|
||||
for (c = 0; c < 4; c++) {
|
||||
if (c < i) {
|
||||
col[c + 0] = m->col[c];
|
||||
col[c + 3] = m->col[c];
|
||||
} else if (c > i) {
|
||||
col[c - 1] = m->col[c];
|
||||
col[c + 2] = m->col[c];
|
||||
}
|
||||
}
|
||||
|
||||
for (r = j; r < 3; r++) {
|
||||
col[0].values[r] = col[0].values[r + 1];
|
||||
col[1].values[r] = col[1].values[r + 1];
|
||||
col[2].values[r] = col[2].values[r + 1];
|
||||
col[3].values[r] = col[3].values[r + 1];
|
||||
col[4].values[r] = col[4].values[r + 1];
|
||||
col[5].values[r] = col[5].values[r + 1];
|
||||
}
|
||||
|
||||
|
||||
/* Calculate the determinant of the resulting 3x3 matrix.
|
||||
*/
|
||||
for (c = 0; c < 3; c++) {
|
||||
double diag1 = col[c].values[0];
|
||||
double diag2 = col[c].values[0];
|
||||
|
||||
for (r = 1; r < 3; r++) {
|
||||
diag1 *= col[(0 + c) + r].values[r];
|
||||
diag2 *= col[(3 + c) - r].values[r];
|
||||
}
|
||||
|
||||
det += (diag1 - diag2);
|
||||
}
|
||||
|
||||
return det;
|
||||
}
|
||||
|
||||
GLfloat gluDeterminant4_4m(const GLUmat4 *m)
|
||||
{
|
||||
double det = 0.0;
|
||||
unsigned c;
|
||||
|
||||
for (c = 0; c < 4; c++) {
|
||||
if (m->col[c].values[3] != 0.0) {
|
||||
/* The usual equation is -1**(i+j) where i and j are
|
||||
* the row and column of the matrix on the range
|
||||
* [1, rows] and [1, cols]. Note that r and c are on
|
||||
* the range [0, rows - 1] and [0, cols - 1].
|
||||
*/
|
||||
const double sign = ((c ^ 3) & 1) ? -1.0 : 1.0;
|
||||
const double d = det3(m, c, 3);
|
||||
|
||||
det += sign * m->col[c].values[3] * d;
|
||||
}
|
||||
}
|
||||
|
||||
return det;
|
||||
}
|
||||
|
||||
|
||||
GLboolean gluInverse4_4m(GLUmat4 *result, const GLUmat4 *m)
|
||||
{
|
||||
const double det = gluDeterminant4_4m(m);
|
||||
double inv_det;
|
||||
unsigned c;
|
||||
unsigned r;
|
||||
|
||||
|
||||
if (det == 0.0)
|
||||
return GL_FALSE;
|
||||
|
||||
inv_det = 1.0 / det;
|
||||
for (c = 0; c < 4; c++) {
|
||||
for (r = 0; r < 4; r++) {
|
||||
/* The usual equation is -1**(i+j) where i and j are
|
||||
* the row and column of the matrix on the range
|
||||
* [1, rows] and [1, cols]. Note that r and c are on
|
||||
* the range [0, rows - 1] and [0, cols - 1].
|
||||
*/
|
||||
const double sign = ((c ^ r) & 1) ? -1.0 : 1.0;
|
||||
const double d = det3(m, c, r);
|
||||
|
||||
result->col[r].values[c] = sign * inv_det * d;
|
||||
}
|
||||
}
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,419 @@
|
|||
/*
|
||||
* es11_example.c
|
||||
*
|
||||
* This code was created by Jeff Molofee '99
|
||||
* (ported to Linux by Ti Leggett '01)
|
||||
* (ported to i.mx51, i.mx31 and x11 by Freescale '10)
|
||||
* If you've found this code useful, please let him know.
|
||||
*
|
||||
* Visit Jeff at http://nehe.gamedev.net/
|
||||
*
|
||||
* Description: Rotating textured 3D object (using OpenGL ES 1.1)
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "GLU3/glu3.h"
|
||||
#include "GLES/gl.h"
|
||||
|
||||
#include "EGL/egl.h"
|
||||
|
||||
#include "FSL/fsl_egl.h"
|
||||
#include "FSL/fslutil.h"
|
||||
|
||||
EGLDisplay egldisplay;
|
||||
EGLConfig eglconfig;
|
||||
EGLSurface eglsurface;
|
||||
EGLContext eglcontext;
|
||||
EGLNativeWindowType eglNativeWindow;
|
||||
EGLNativeDisplayType eglNativeDisplayType;
|
||||
volatile sig_atomic_t quit = 0;
|
||||
|
||||
GLfloat xrot; /* X Rotation ( NEW ) */
|
||||
GLfloat yrot; /* Y Rotation ( NEW ) */
|
||||
GLfloat zrot; /* Z Rotation ( NEW ) */
|
||||
|
||||
GLuint texture[1]; /* Storage For One Texture ( NEW ) */
|
||||
|
||||
/* function to load in bitmap as a GL texture */
|
||||
int LoadGLTextures()
|
||||
{
|
||||
Image *image1;
|
||||
|
||||
// allocate space for texture we will use
|
||||
image1 = (Image *) malloc(sizeof(Image));
|
||||
if (image1 == NULL) {
|
||||
printf("Error allocating space for image\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit */
|
||||
if (LoadBMP("texture.bmp", image1)) {
|
||||
/* Create The Texture */
|
||||
glGenTextures(1, texture);
|
||||
/* Typical Texture Generation Using Data From The Bitmap */
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
/* Generate The Texture */
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image1->sizeX, image1->sizeY, 0, GL_RGB,
|
||||
GL_UNSIGNED_BYTE, image1->data);
|
||||
/* Linear Filtering */
|
||||
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Free up any memory we may have used */
|
||||
if (image1 != NULL) {
|
||||
free(image1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Here goes our drawing code */
|
||||
void render()
|
||||
{
|
||||
/* These are to calculate our fps */
|
||||
GLfloat texcoords[4][2];
|
||||
GLfloat vertices[4][3];
|
||||
GLubyte indices[4] = { 0, 1, 3, 2 }; /* QUAD to TRIANGLE_STRIP conversion; */
|
||||
|
||||
/* Clear The Screen And The Depth Buffer */
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
/* Move Into The Screen 5 Units */
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.0f, 0.0f, -5.0f);
|
||||
|
||||
glRotatef(xrot, 1.0f, 0.0f, 0.0f); /* Rotate On The X Axis */
|
||||
glRotatef(yrot, 0.0f, 1.0f, 0.0f); /* Rotate On The Y Axis */
|
||||
glRotatef(zrot, 0.0f, 0.0f, 1.0f); /* Rotate On The Z Axis */
|
||||
|
||||
/* Select Our Texture */
|
||||
glBindTexture(GL_TEXTURE_2D, texture[0]);
|
||||
|
||||
/* Set pointers to vertices and texcoords */
|
||||
glVertexPointer(3, GL_FLOAT, 0, vertices);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
|
||||
|
||||
/* Enable vertices and texcoords arrays */
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
/* Front Face */
|
||||
texcoords[0][0] = 0.0f;
|
||||
texcoords[0][1] = 0.0f;
|
||||
vertices[0][0] = -1.0f;
|
||||
vertices[0][1] = -1.0f;
|
||||
vertices[0][2] = 1.0f;
|
||||
texcoords[1][0] = 1.0f;
|
||||
texcoords[1][1] = 0.0f;
|
||||
vertices[1][0] = 1.0f;
|
||||
vertices[1][1] = -1.0f;
|
||||
vertices[1][2] = 1.0f;
|
||||
texcoords[2][0] = 1.0f;
|
||||
texcoords[2][1] = 1.0f;
|
||||
vertices[2][0] = 1.0f;
|
||||
vertices[2][1] = 1.0f;
|
||||
vertices[2][2] = 1.0f;
|
||||
texcoords[3][0] = 0.0f;
|
||||
texcoords[3][1] = 1.0f;
|
||||
vertices[3][0] = -1.0f;
|
||||
vertices[3][1] = 1.0f;
|
||||
vertices[3][2] = 1.0f;
|
||||
|
||||
/* Draw one textured plane using two stripped triangles */
|
||||
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);
|
||||
|
||||
/* Back Face */
|
||||
/* Normal Pointing Away From Viewer */
|
||||
texcoords[0][0] = 0.0f;
|
||||
texcoords[0][1] = 1.0f;
|
||||
vertices[0][0] = -1.0f;
|
||||
vertices[0][1] = -1.0f;
|
||||
vertices[0][2] = -1.0f;
|
||||
texcoords[1][0] = 0.0f;
|
||||
texcoords[1][1] = 0.0f;
|
||||
vertices[1][0] = -1.0f;
|
||||
vertices[1][1] = 1.0f;
|
||||
vertices[1][2] = -1.0f;
|
||||
texcoords[2][0] = 1.0f;
|
||||
texcoords[2][1] = 0.0f;
|
||||
vertices[2][0] = 1.0f;
|
||||
vertices[2][1] = 1.0f;
|
||||
vertices[2][2] = -1.0f;
|
||||
texcoords[3][0] = 1.0f;
|
||||
texcoords[3][1] = 1.0f;
|
||||
vertices[3][0] = 1.0f;
|
||||
vertices[3][1] = -1.0f;
|
||||
vertices[3][2] = -1.0f;
|
||||
|
||||
/* Draw one textured plane using two stripped triangles */
|
||||
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);
|
||||
|
||||
/* Top Face */
|
||||
texcoords[0][0] = 1.0f;
|
||||
texcoords[0][1] = 0.0f;
|
||||
vertices[0][0] = -1.0f;
|
||||
vertices[0][1] = 1.0f;
|
||||
vertices[0][2] = -1.0f;
|
||||
texcoords[1][0] = 1.0f;
|
||||
texcoords[1][1] = 1.0f;
|
||||
vertices[1][0] = -1.0f;
|
||||
vertices[1][1] = 1.0f;
|
||||
vertices[1][2] = 1.0f;
|
||||
texcoords[2][0] = 0.0f;
|
||||
texcoords[2][1] = 1.0f;
|
||||
vertices[2][0] = 1.0f;
|
||||
vertices[2][1] = 1.0f;
|
||||
vertices[2][2] = 1.0f;
|
||||
texcoords[3][0] = 0.0f;
|
||||
texcoords[3][1] = 0.0f;
|
||||
vertices[3][0] = 1.0f;
|
||||
vertices[3][1] = 1.0f;
|
||||
vertices[3][2] = -1.0f;
|
||||
|
||||
/* Draw one textured plane using two stripped triangles */
|
||||
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);
|
||||
|
||||
/* Bottom Face */
|
||||
texcoords[0][0] = 1.0f;
|
||||
texcoords[0][1] = 1.0f;
|
||||
vertices[0][0] = -1.0f;
|
||||
vertices[0][1] = -1.0f;
|
||||
vertices[0][2] = -1.0f;
|
||||
texcoords[1][0] = 0.0f;
|
||||
texcoords[1][1] = 1.0f;
|
||||
vertices[1][0] = 1.0f;
|
||||
vertices[1][1] = -1.0f;
|
||||
vertices[1][2] = -1.0f;
|
||||
texcoords[2][0] = 0.0f;
|
||||
texcoords[2][1] = 0.0f;
|
||||
vertices[2][0] = 1.0f;
|
||||
vertices[2][1] = -1.0f;
|
||||
vertices[2][2] = 1.0f;
|
||||
texcoords[3][0] = 1.0f;
|
||||
texcoords[3][1] = 0.0f;
|
||||
vertices[3][0] = -1.0f;
|
||||
vertices[3][1] = -1.0f;
|
||||
vertices[3][2] = 1.0f;
|
||||
|
||||
/* Draw one textured plane using two stripped triangles */
|
||||
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);
|
||||
|
||||
/* Right face */
|
||||
texcoords[0][0] = 0.0f;
|
||||
texcoords[0][1] = 1.0f;
|
||||
vertices[0][0] = 1.0f;
|
||||
vertices[0][1] = -1.0f;
|
||||
vertices[0][2] = -1.0f;
|
||||
texcoords[1][0] = 0.0f;
|
||||
texcoords[1][1] = 0.0f;
|
||||
vertices[1][0] = 1.0f;
|
||||
vertices[1][1] = 1.0f;
|
||||
vertices[1][2] = -1.0f;
|
||||
texcoords[2][0] = 1.0f;
|
||||
texcoords[2][1] = 0.0f;
|
||||
vertices[2][0] = 1.0f;
|
||||
vertices[2][1] = 1.0f;
|
||||
vertices[2][2] = 1.0f;
|
||||
texcoords[3][0] = 1.0f;
|
||||
texcoords[3][1] = 1.0f;
|
||||
vertices[3][0] = 1.0f;
|
||||
vertices[3][1] = -1.0f;
|
||||
vertices[3][2] = 1.0f;
|
||||
|
||||
/* Draw one textured plane using two stripped triangles */
|
||||
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);
|
||||
|
||||
/* Left Face */
|
||||
texcoords[0][0] = 0.0f;
|
||||
texcoords[0][1] = 0.0f;
|
||||
vertices[0][0] = -1.0f;
|
||||
vertices[0][1] = -1.0f;
|
||||
vertices[0][2] = -1.0f;
|
||||
texcoords[1][0] = 1.0f;
|
||||
texcoords[1][1] = 0.0f;
|
||||
vertices[1][0] = -1.0f;
|
||||
vertices[1][1] = -1.0f;
|
||||
vertices[1][2] = 1.0f;
|
||||
texcoords[2][0] = 1.0f;
|
||||
texcoords[2][1] = 1.0f;
|
||||
vertices[2][0] = -1.0f;
|
||||
vertices[2][1] = 1.0f;
|
||||
vertices[2][2] = 1.0f;
|
||||
texcoords[3][0] = 0.0f;
|
||||
texcoords[3][1] = 1.0f;
|
||||
vertices[3][0] = -1.0f;
|
||||
vertices[3][1] = 1.0f;
|
||||
vertices[3][2] = -1.0f;
|
||||
|
||||
/* Draw one textured plane using two stripped triangles */
|
||||
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices);
|
||||
|
||||
/* Disable texcoords and vertices arrays */
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
/* Flush all drawings */
|
||||
glFinish();
|
||||
|
||||
xrot += 0.3f; /* X Axis Rotation */
|
||||
yrot += 0.2f; /* Y Axis Rotation */
|
||||
zrot += 0.4f; /* Z Axis Rotation */
|
||||
}
|
||||
|
||||
void resize(int w, int h)
|
||||
{
|
||||
/*change to projection matrix */
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
/*reset the projection matrix */
|
||||
glLoadIdentity();
|
||||
/*set the viewport */
|
||||
glViewport(0, 0, w, h);
|
||||
|
||||
GLUmat4 perspective;
|
||||
/*use glu to set perspective */
|
||||
gluPerspective4f(&perspective, 45.0f, ((GLfloat) w / (GLfloat) h), 1.0f, 100.0f);
|
||||
glMultMatrixf(&perspective.col[0].values[0]);
|
||||
|
||||
/*get back to model view matrix */
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
/*reset modevl view matrix */
|
||||
glLoadIdentity();
|
||||
}
|
||||
|
||||
int init(void)
|
||||
{
|
||||
int w = 640;
|
||||
int h = 480;
|
||||
|
||||
static const EGLint s_configAttribs[] = {
|
||||
EGL_RED_SIZE, 5,
|
||||
EGL_GREEN_SIZE, 6,
|
||||
EGL_BLUE_SIZE, 5,
|
||||
EGL_ALPHA_SIZE, 0,
|
||||
EGL_SAMPLES, 0,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
EGLint numconfigs;
|
||||
|
||||
//get egl display
|
||||
eglNativeDisplayType = fsl_getNativeDisplay();
|
||||
egldisplay = eglGetDisplay(eglNativeDisplayType);
|
||||
//Initialize egl
|
||||
eglInitialize(egldisplay, NULL, NULL);
|
||||
assert(eglGetError() == EGL_SUCCESS);
|
||||
//tell the driver we are using OpenGL ES
|
||||
eglBindAPI(EGL_OPENGL_ES_API);
|
||||
|
||||
//pass our egl configuration to egl
|
||||
eglChooseConfig(egldisplay, s_configAttribs, &eglconfig, 1, &numconfigs);
|
||||
printf("chooseconfig, \n");
|
||||
assert(eglGetError() == EGL_SUCCESS);
|
||||
assert(numconfigs == 1);
|
||||
/* Enable smooth shading */
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
eglNativeWindow = fsl_createwindow(egldisplay, eglNativeDisplayType);
|
||||
assert(eglNativeWindow);
|
||||
|
||||
eglsurface =
|
||||
eglCreateWindowSurface(egldisplay, eglconfig, (EGLNativeWindowType) eglNativeWindow,
|
||||
NULL);
|
||||
|
||||
printf("createwindow, \n");
|
||||
assert(eglGetError() == EGL_SUCCESS);
|
||||
|
||||
//create the egl graphics context
|
||||
eglcontext = eglCreateContext(egldisplay, eglconfig, NULL, NULL);
|
||||
printf("creatcontext, \n");
|
||||
assert(eglGetError() == EGL_SUCCESS);
|
||||
|
||||
//make the context current
|
||||
eglMakeCurrent(egldisplay, eglsurface, eglsurface, eglcontext);
|
||||
printf("makecurrent, \n");
|
||||
assert(eglGetError() == EGL_SUCCESS);
|
||||
|
||||
/* Load in the texture */
|
||||
if (LoadGLTextures() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Enable Texture Mapping ( NEW ) */
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
/* Enable smooth shading */
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
/* Set the background black */
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
|
||||
|
||||
/* Depth buffer setup */
|
||||
glClearDepthf(1.0f);
|
||||
|
||||
/* Enables Depth Testing */
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
/* The Type Of Depth Test To Do */
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
/*enable cullface */
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
/* Really Nice Perspective Calculations */
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
|
||||
/*get width and height from egl */
|
||||
eglQuerySurface(egldisplay, eglsurface, EGL_WIDTH, &w);
|
||||
eglQuerySurface(egldisplay, eglsurface, EGL_HEIGHT, &h);
|
||||
|
||||
/* Scale the content to the window */
|
||||
resize(w, h);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void deinit(void)
|
||||
{
|
||||
printf("Cleaning up...\n");
|
||||
eglMakeCurrent(egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
assert(eglGetError() == EGL_SUCCESS);
|
||||
eglDestroyContext(egldisplay, eglcontext);
|
||||
eglDestroySurface(egldisplay, eglsurface);
|
||||
fsl_destroywindow(eglNativeWindow, eglNativeDisplayType);
|
||||
eglTerminate(egldisplay);
|
||||
assert(eglGetError() == EGL_SUCCESS);
|
||||
eglReleaseThread();
|
||||
}
|
||||
|
||||
void sighandler(int signal)
|
||||
{
|
||||
printf("Caught signal %d, setting flaq to quit.\n", signal);
|
||||
quit = 1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
signal(SIGINT, sighandler);
|
||||
signal(SIGTERM, sighandler);
|
||||
|
||||
assert(init());
|
||||
while (!quit) {
|
||||
render();
|
||||
eglSwapBuffers(egldisplay, eglsurface);
|
||||
}
|
||||
deinit();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,488 @@
|
|||
/*
|
||||
* This code was created by Jeff Molofee '99
|
||||
* (ported to Linux by Ti Leggett '01)
|
||||
* (ported to i.mx51, i.mx31 and x11 by Freescale '10)
|
||||
* If you've found this code useful, please let him know.
|
||||
*
|
||||
* Visit Jeff at http://nehe.gamedev.net/
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "GLES2/gl2.h"
|
||||
#include "GLES2/gl2ext.h"
|
||||
|
||||
#include "EGL/egl.h"
|
||||
|
||||
#include "FSL/fsl_egl.h"
|
||||
#include "FSL/fslutil.h"
|
||||
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE !TRUE
|
||||
EGLDisplay egldisplay;
|
||||
EGLConfig eglconfig;
|
||||
EGLSurface eglsurface;
|
||||
EGLContext eglcontext;
|
||||
EGLNativeWindowType eglNativeWindow;
|
||||
EGLNativeDisplayType eglNativeDisplayType;
|
||||
volatile sig_atomic_t quit = 0;
|
||||
|
||||
GLuint g_hShaderProgram = 0;
|
||||
GLuint g_hModelViewMatrixLoc = 0;
|
||||
GLuint g_hProjMatrixLoc = 0;
|
||||
GLuint g_hVertexLoc = 0;
|
||||
GLuint g_hVertexTexLoc = 2;
|
||||
GLuint g_hColorLoc = 1;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Name: g_strVertexShader / g_strFragmentShader
|
||||
// Desc: The vertex and fragment shader programs
|
||||
//--------------------------------------------------------------------------------------
|
||||
const char* g_strVertexShader =
|
||||
"uniform mat4 g_matModelView; \n"
|
||||
"uniform mat4 g_matProj; \n"
|
||||
" \n"
|
||||
"attribute vec4 g_vPosition; \n"
|
||||
"attribute vec3 g_vColor; \n"
|
||||
"attribute vec2 g_vTexCoord; \n"
|
||||
" \n"
|
||||
"varying vec3 g_vVSColor; \n"
|
||||
"varying vec2 g_vVSTexCoord; \n"
|
||||
" \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" vec4 vPositionES = g_matModelView * g_vPosition; \n"
|
||||
" gl_Position = g_matProj * vPositionES; \n"
|
||||
" g_vVSColor = g_vColor; \n"
|
||||
" g_vVSTexCoord = g_vTexCoord; \n"
|
||||
"} \n";
|
||||
|
||||
|
||||
const char* g_strFragmentShader =
|
||||
"#ifdef GL_FRAGMENT_PRECISION_HIGH \n"
|
||||
" precision highp float; \n"
|
||||
"#else \n"
|
||||
" precision mediump float; \n"
|
||||
"#endif \n"
|
||||
" \n"
|
||||
"uniform sampler2D s_texture; \n"
|
||||
"varying vec3 g_vVSColor; \n"
|
||||
"varying vec2 g_vVSTexCoord; \n"
|
||||
" \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" gl_FragColor = texture2D(s_texture,g_vVSTexCoord); \n"
|
||||
"} \n";
|
||||
|
||||
float VertexPositions[] = {
|
||||
/* Draw A Quad */
|
||||
/* Top Right Of The Quad (Top) */
|
||||
1.0f, 1.0f, -1.0f,
|
||||
/* Top Left Of The Quad (Top) */
|
||||
-1.0f, 1.0f, -1.0f,
|
||||
/* Bottom Right Of The Quad (Top) */
|
||||
1.0f, 1.0f, 1.0f,
|
||||
/* Bottom Left Of The Quad (Top) */
|
||||
-1.0f, 1.0f, 1.0f,
|
||||
/* Top Right Of The Quad (Bottom) */
|
||||
1.0f, -1.0f, 1.0f,
|
||||
/* Top Left Of The Quad (Bottom) */
|
||||
-1.0f, -1.0f, 1.0f,
|
||||
/* Bottom Right Of The Quad (Bottom) */
|
||||
1.0f, -1.0f, -1.0f,
|
||||
/* Bottom Left Of The Quad (Bottom) */
|
||||
-1.0f, -1.0f, -1.0f,
|
||||
/* Top Right Of The Quad (Front) */
|
||||
1.0f, 1.0f, 1.0f,
|
||||
/* Top Left Of The Quad (Front) */
|
||||
-1.0f, 1.0f, 1.0f,
|
||||
/* Bottom Right Of The Quad (Front) */
|
||||
1.0f, -1.0f, 1.0f,
|
||||
/* Bottom Left Of The Quad (Front) */
|
||||
-1.0f, -1.0f, 1.0f,
|
||||
/* Top Right Of The Quad (Back) */
|
||||
1.0f, -1.0f, -1.0f,
|
||||
/* Top Left Of The Quad (Back) */
|
||||
-1.0f, -1.0f, -1.0f,
|
||||
/* Bottom Right Of The Quad (Back) */
|
||||
1.0f, 1.0f, -1.0f,
|
||||
/* Bottom Left Of The Quad (Back) */
|
||||
-1.0f, 1.0f, -1.0f,
|
||||
/* Top Right Of The Quad (Left) */
|
||||
-1.0f, 1.0f, 1.0f,
|
||||
/* Top Left Of The Quad (Left) */
|
||||
-1.0f, 1.0f, -1.0f,
|
||||
/* Bottom Right Of The Quad (Left) */
|
||||
-1.0f, -1.0f, 1.0f,
|
||||
/* Bottom Left Of The Quad (Left) */
|
||||
-1.0f, -1.0f, -1.0f,
|
||||
/* Top Right Of The Quad (Right) */
|
||||
1.0f, 1.0f, -1.0f,
|
||||
/* Top Left Of The Quad (Right) */
|
||||
1.0f, 1.0f, 1.0f,
|
||||
/* Bottom Right Of The Quad (Right) */
|
||||
1.0f, -1.0f, -1.0f,
|
||||
/* Bottom Left Of The Quad (Right) */
|
||||
1.0f, -1.0f, 1.0f
|
||||
};
|
||||
|
||||
float VertexTexCoords[] = {
|
||||
/* Top Face */
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
/* Bottom Face */
|
||||
1.0f, 1.0f,
|
||||
0.0f, 1.0f,
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
/* Front Face */
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
/* Back Face */
|
||||
1.0f, 1.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 0.0f,
|
||||
/*left face */
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
/* Right face */
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
};
|
||||
|
||||
float VertexColors[] = {
|
||||
/* Red */
|
||||
1.0f, 0.0f, 0.0f, 1.0f,
|
||||
/* Red */
|
||||
1.0f, 0.0f, 0.0f, 1.0f,
|
||||
/* Green */
|
||||
0.0f, 1.0f, 0.0f, 1.0f,
|
||||
/* Green */
|
||||
0.0f, 1.0f, 0.0f, 1.0f,
|
||||
/* Blue */
|
||||
0.0f, 0.0f, 1.0f, 1.0f,
|
||||
/* Blue */
|
||||
0.0f, 0.0f, 1.0f, 1.0f,
|
||||
/* Red */
|
||||
1.0f, 0.0, 0.0f, 1.0f,
|
||||
/* Red */
|
||||
1.0f, 0.0, 0.0f, 1.0f,
|
||||
/* Blue */
|
||||
0.0f, 0.0f, 1.0f, 1.0f,
|
||||
/* Blue */
|
||||
0.0f, 0.0f, 1.0f, 1.0f,
|
||||
/* Green */
|
||||
0.0f, 1.0f, 0.0f, 1.0f,
|
||||
/* Green */
|
||||
0.0f, 1.0f, 0.0f, 1.0f,
|
||||
/* Red */
|
||||
1.0f, 0.0f, 0.0f, 1.0f,
|
||||
/* Red */
|
||||
1.0f, 0.0f, 0.0f, 1.0f,
|
||||
/* Green */
|
||||
0.0f, 1.0f, 0.0f, 1.0f,
|
||||
/* Green */
|
||||
0.0f, 1.0f, 0.0f, 1.0f,
|
||||
/* Blue */
|
||||
0.0f, 0.0f, 1.0f, 1.0f,
|
||||
/* Blue */
|
||||
0.0f, 0.0f, 1.0f, 1.0f,
|
||||
/* Red */
|
||||
1.0f, 0.0f, 0.0f, 1.0f,
|
||||
/* Red */
|
||||
1.0f, 0.0f, 0.0f, 1.0f,
|
||||
/* Blue */
|
||||
0.0f, 0.0f, 1.0f, 1.0f,
|
||||
/* Green */
|
||||
0.0f, 1.0f, 0.0f, 1.0f,
|
||||
/* Blue */
|
||||
0.0f, 0.0f, 1.0f, 1.0f,
|
||||
/* Green */
|
||||
0.0f, 1.0f, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
GLuint texture[1]; /* Storage For One Texture ( NEW ) */
|
||||
|
||||
/* function to load in bitmap as a GL texture */
|
||||
int LoadGLTextures()
|
||||
{
|
||||
|
||||
Image *image1;
|
||||
|
||||
// allocate space for texture we will use
|
||||
image1 = (Image *) malloc(sizeof(Image));
|
||||
if (image1 == NULL) {
|
||||
printf("Error allocating space for image");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit */
|
||||
if (LoadBMP("texture.bmp", image1)) {
|
||||
/* Create The Texture */
|
||||
glGenTextures(1, texture);
|
||||
/* Typical Texture Generation Using Data From The Bitmap */
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
/* Generate The Texture */
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image1->sizeX, image1->sizeY, 0, GL_RGB,
|
||||
GL_UNSIGNED_BYTE, image1->data);
|
||||
/* Linear Filtering */
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
printf("texture loaded and created successfully");
|
||||
|
||||
} else
|
||||
return 0;
|
||||
|
||||
/* Free up any memory we may have used */
|
||||
if (image1 != NULL) {
|
||||
free(image1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void render(float w, float h)
|
||||
{
|
||||
static float fAngle = 0.0f;
|
||||
fAngle += 0.01f;
|
||||
|
||||
// Rotate and translate the model view matrix
|
||||
float matModelView[16] = { 0 };
|
||||
matModelView[0] = +cosf(fAngle);
|
||||
matModelView[2] = +sinf(fAngle);
|
||||
matModelView[5] = 1.0f;
|
||||
matModelView[8] = -sinf(fAngle);
|
||||
matModelView[10] = +cosf(fAngle);
|
||||
matModelView[12] = 0.0f; //X
|
||||
matModelView[14] = -6.0f; //z
|
||||
matModelView[15] = 1.0f;
|
||||
|
||||
// Build a perspective projection matrix
|
||||
float matProj[16] = { 0 };
|
||||
matProj[0] = cosf(0.5f) / sinf(0.5f);
|
||||
matProj[5] = matProj[0] * (w / h);
|
||||
matProj[10] = -(10.0f) / (9.0f);
|
||||
matProj[11] = -1.0f;
|
||||
matProj[14] = -(10.0f) / (9.0f);
|
||||
|
||||
// Clear the colorbuffer and depth-buffer
|
||||
glClearColor(0.0f, 0.0f, 0.5f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Set some state
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
// Set the shader program
|
||||
glUseProgram(g_hShaderProgram);
|
||||
glUniformMatrix4fv(g_hModelViewMatrixLoc, 1, 0, matModelView);
|
||||
glUniformMatrix4fv(g_hProjMatrixLoc, 1, 0, matProj);
|
||||
|
||||
// Bind the vertex attributes
|
||||
glVertexAttribPointer(g_hVertexLoc, 3, GL_FLOAT, 0, 0, VertexPositions);
|
||||
glEnableVertexAttribArray(g_hVertexLoc);
|
||||
|
||||
glVertexAttribPointer(g_hColorLoc, 4, GL_FLOAT, 0, 0, VertexColors);
|
||||
glEnableVertexAttribArray(g_hColorLoc);
|
||||
|
||||
glVertexAttribPointer(g_hVertexTexLoc, 2, GL_FLOAT, 0, 0, VertexTexCoords);
|
||||
glEnableVertexAttribArray(g_hVertexTexLoc);
|
||||
|
||||
/* Select Our Texture */
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture[0]);
|
||||
|
||||
/* Drawing Using Triangle strips, draw triangle strips using 4 vertices */
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 12, 4);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 16, 4);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 20, 4);
|
||||
|
||||
// Cleanup
|
||||
glDisableVertexAttribArray(g_hVertexLoc);
|
||||
glDisableVertexAttribArray(g_hColorLoc);
|
||||
glDisableVertexAttribArray(g_hVertexTexLoc);
|
||||
}
|
||||
|
||||
|
||||
int init(void)
|
||||
{
|
||||
|
||||
/*static const EGLint gl_context_attribs[] =
|
||||
{
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
}; */
|
||||
|
||||
static const EGLint s_configAttribs[] = {
|
||||
EGL_RED_SIZE, 5,
|
||||
EGL_GREEN_SIZE, 6,
|
||||
EGL_BLUE_SIZE, 5,
|
||||
EGL_ALPHA_SIZE, 0,
|
||||
EGL_SAMPLES, 0,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
EGLint numconfigs;
|
||||
|
||||
eglNativeDisplayType = fsl_getNativeDisplay();
|
||||
egldisplay = eglGetDisplay(eglNativeDisplayType);
|
||||
eglInitialize(egldisplay, NULL, NULL);
|
||||
assert(eglGetError() == EGL_SUCCESS);
|
||||
eglBindAPI(EGL_OPENGL_ES_API);
|
||||
|
||||
eglChooseConfig(egldisplay, s_configAttribs, &eglconfig, 1, &numconfigs);
|
||||
assert(eglGetError() == EGL_SUCCESS);
|
||||
assert(numconfigs == 1);
|
||||
|
||||
eglNativeWindow = fsl_createwindow(egldisplay, eglNativeDisplayType);
|
||||
assert(eglNativeWindow);
|
||||
|
||||
eglsurface = eglCreateWindowSurface(egldisplay, eglconfig, eglNativeWindow, NULL);
|
||||
|
||||
assert(eglGetError() == EGL_SUCCESS);
|
||||
EGLint ContextAttribList[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
|
||||
|
||||
eglcontext = eglCreateContext(egldisplay, eglconfig, EGL_NO_CONTEXT, ContextAttribList);
|
||||
assert(eglGetError() == EGL_SUCCESS);
|
||||
eglMakeCurrent(egldisplay, eglsurface, eglsurface, eglcontext);
|
||||
assert(eglGetError() == EGL_SUCCESS);
|
||||
|
||||
{
|
||||
// Compile the shaders
|
||||
GLuint hVertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(hVertexShader, 1, &g_strVertexShader, NULL);
|
||||
glCompileShader(hVertexShader);
|
||||
|
||||
// Check for compile success
|
||||
GLint nCompileResult = 0;
|
||||
glGetShaderiv(hVertexShader, GL_COMPILE_STATUS, &nCompileResult);
|
||||
if (0 == nCompileResult) {
|
||||
char strLog[1024];
|
||||
GLint nLength;
|
||||
glGetShaderInfoLog(hVertexShader, 1024, &nLength, strLog);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GLuint hFragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(hFragmentShader, 1, &g_strFragmentShader, NULL);
|
||||
glCompileShader(hFragmentShader);
|
||||
|
||||
// Check for compile success
|
||||
glGetShaderiv(hFragmentShader, GL_COMPILE_STATUS, &nCompileResult);
|
||||
if (0 == nCompileResult) {
|
||||
char strLog[1024];
|
||||
GLint nLength;
|
||||
glGetShaderInfoLog(hFragmentShader, 1024, &nLength, strLog);
|
||||
return FALSE;
|
||||
}
|
||||
// Attach the individual shaders to the common shader program
|
||||
g_hShaderProgram = glCreateProgram();
|
||||
glAttachShader(g_hShaderProgram, hVertexShader);
|
||||
glAttachShader(g_hShaderProgram, hFragmentShader);
|
||||
|
||||
// Init attributes BEFORE linking
|
||||
glBindAttribLocation(g_hShaderProgram, g_hVertexLoc, "g_vPosition");
|
||||
glBindAttribLocation(g_hShaderProgram, g_hColorLoc, "g_vColor");
|
||||
|
||||
printf("about to link shader...");
|
||||
glBindAttribLocation(g_hShaderProgram, g_hVertexTexLoc, "g_vTexCoord");
|
||||
|
||||
// Link the vertex shader and fragment shader together
|
||||
glLinkProgram(g_hShaderProgram);
|
||||
|
||||
// Check for link success
|
||||
GLint nLinkResult = 0;
|
||||
glGetProgramiv(g_hShaderProgram, GL_LINK_STATUS, &nLinkResult);
|
||||
if (0 == nLinkResult) {
|
||||
char strLog[1024];
|
||||
GLint nLength;
|
||||
glGetProgramInfoLog(g_hShaderProgram, 1024, &nLength, strLog);
|
||||
printf("error linking shader");
|
||||
return FALSE;
|
||||
}
|
||||
// Get uniform locations
|
||||
g_hModelViewMatrixLoc =
|
||||
glGetUniformLocation(g_hShaderProgram, "g_matModelView");
|
||||
g_hProjMatrixLoc = glGetUniformLocation(g_hShaderProgram, "g_matProj");
|
||||
|
||||
glDeleteShader(hVertexShader);
|
||||
glDeleteShader(hFragmentShader);
|
||||
|
||||
//gen textures
|
||||
/* Load in the texture */
|
||||
if (LoadGLTextures() == 0) {
|
||||
printf("error loading texture");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Enable Texture Mapping ( NEW ) */
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Cleanup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void deinit(void)
|
||||
{
|
||||
printf("Cleaning up...\n");
|
||||
Cleanup();
|
||||
eglMakeCurrent(egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
assert(eglGetError() == EGL_SUCCESS);
|
||||
eglDestroyContext(egldisplay, eglcontext);
|
||||
eglDestroySurface(egldisplay, eglsurface);
|
||||
fsl_destroywindow(eglNativeWindow, eglNativeDisplayType);
|
||||
eglTerminate(egldisplay);
|
||||
assert(eglGetError() == EGL_SUCCESS);
|
||||
eglReleaseThread();
|
||||
}
|
||||
|
||||
void sighandler(int signal)
|
||||
{
|
||||
printf("Caught signal %d, setting flaq to quit.\n", signal);
|
||||
quit = 1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
signal(SIGINT, sighandler);
|
||||
signal(SIGTERM, sighandler);
|
||||
assert(init());
|
||||
|
||||
while (!quit) {
|
||||
EGLint width = 0;
|
||||
EGLint height = 0;
|
||||
eglQuerySurface(egldisplay, eglsurface, EGL_WIDTH, &width);
|
||||
eglQuerySurface(egldisplay, eglsurface, EGL_HEIGHT, &height);
|
||||
render(width, height);
|
||||
eglSwapBuffers(egldisplay, eglsurface);
|
||||
}
|
||||
deinit();
|
||||
return 0;
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 192 KiB |
|
|
@ -46,6 +46,7 @@ RDEPENDS_${PN}_append_ccimx53js = "\
|
|||
|
||||
RDEPENDS_${PN}_append_mx6 = "\
|
||||
dey-examples-can \
|
||||
${@base_contains("MACHINE_FEATURES", "accel-graphics", "dey-examples-opengles", "", d)} \
|
||||
dey-examples-v4l2 \
|
||||
"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue