-
/* -------------------------------------------------------------------------- */
#include <kernelapi.h>
/* -------------------------------------------------------------------------- */
-EGLNativeDisplayType eglX11Display;
-EGLNativeWindowType eglX11Window;
-EGLDisplay eglDisplay = 0;
-EGLConfig eglConfig = 0;
-EGLSurface eglSurface = 0;
-EGLContext eglContext = 0;
-
-/* -------------------------------------------------------------------------- */
+static GLfloat xco= 0;
+static GLfloat yco= 1;
+static GLfloat zco= -35;
+static GLfloat view_rotx=0.0, view_roty=0.0, view_rotz=0.0;
+static int shift=0;
-#define GLfloat float
-static GLfloat xco= 0;
-static GLfloat yco= 1;
-static GLfloat zco= -35;
-static GLfloat view_rotx=0.0, view_roty=0.0, view_rotz=0.0;
-static int shift=0;
+GLuint program;
+GLuint texture;
+GLuint vbo;
+unsigned int numberOfVertices;
+unsigned int posStep;
+unsigned int normStep;
+unsigned int tcStep;
+unsigned int stride;
+float angle=0.0;
+float viewAngle = 0.0;
/* -------------------------------------------------------------------------- */
static void draw(void);
static void key(unsigned char k, int down);
-static void destroyEGL();
-static int getX11Display(int windowwidth, int windowheight);
-static int setUpEGL();
static int useTheProgram();
static int setUpTnL();
static int drawStuff(int width, int height);
EXPORT int mid_module_tick(void)
{
- if(!drawStuff(WINDOW_WIDTH, WINDOW_HEIGHT)) destroyEGL();
+ if(!drawStuff(WINDOW_WIDTH, WINDOW_HEIGHT)) k_gl_end();
return 1;
}
void init_gl(void)
{
- if(!getX11Display(WINDOW_WIDTH, WINDOW_HEIGHT)) destroyEGL();
- if(!setUpEGL()) destroyEGL();
- if(!useTheProgram()) destroyEGL();
- if(!setUpTnL()) destroyEGL();
+ if(!useTheProgram()) k_gl_end();
+ if(!setUpTnL()) k_gl_end();
}
void reshape(int width, int height)
void draw(void)
{
- if(!drawStuff(WINDOW_WIDTH, WINDOW_HEIGHT)) destroyEGL();
+ if(!drawStuff(WINDOW_WIDTH, WINDOW_HEIGHT)) k_gl_end();
}
#define SHIFT 0
void key(unsigned char k, int down)
{
-/*
- if(event.xkey.keycode == 113) viewAngle += 0.1;
- if(event.xkey.keycode == 114) viewAngle -= 0.1;
-*/
+ if(k == 113) viewAngle += 0.1;
+ if(k == 114) viewAngle -= 0.1;
+
if(k==SHIFT && down){ shift=1; return; }
if(k==SHIFT && !down){ shift=0; return; }
if(!down) return;
draw();
}
-/* -------------------------------------------------------------------------- */
-
-/* need a callback to call this */
-void destroyEGL()
-{
- eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
- eglTerminate(eglDisplay);
-}
-
-/* ------------------------------------------------------------- */
-
-int isEGLError(char* where)
-{
- EGLint err = eglGetError();
- if(err != EGL_SUCCESS) {
- printf("EGL failed at %s (%d).\n", where, err);
- return 1;
- }
- return 0;
-}
-
-int setUpEGL()
-{
- eglDisplay = eglGetDisplay(eglX11Display);
-
- EGLint iMajorVersion, iMinorVersion;
- if(!eglInitialize(eglDisplay, &iMajorVersion, &iMinorVersion)) {
- printf("Error: eglInitialize() failed.\n");
- return 0;
- }
-
- EGLint pi32ConfigAttribs[5];
- pi32ConfigAttribs[0] = EGL_SURFACE_TYPE;
- pi32ConfigAttribs[1] = EGL_WINDOW_BIT;
- pi32ConfigAttribs[2] = EGL_RENDERABLE_TYPE;
- pi32ConfigAttribs[3] = EGL_OPENGL_ES2_BIT;
- pi32ConfigAttribs[4] = EGL_NONE;
-
- EGLint pi32ContextAttribs[3];
- pi32ContextAttribs[0] = EGL_CONTEXT_CLIENT_VERSION;
- pi32ContextAttribs[1] = 2;
- pi32ContextAttribs[2] = EGL_NONE;
-
- int iConfigs;
- if(!eglChooseConfig(eglDisplay, pi32ConfigAttribs, &eglConfig, 1, &iConfigs) || (iConfigs != 1)) {
- printf("Error: eglChooseConfig() failed.\n");
- return 0;
- }
-
- eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, eglX11Window, NULL);
- if(isEGLError("eglCreateWindowSurface")) return 0;
-
- eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, pi32ContextAttribs);
- if(isEGLError("eglCreateContext")) return 0;
-
- eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
- if(isEGLError("eglMakeCurrent")) return 0;
-
- return 1;
-}
-
/* ------------------------------------------------------------- */
GLuint isShaderError(GLuint thing)
/* ------------------------------------------------------------- */
-GLuint program;
-GLuint texture;
-GLuint vbo;
-unsigned int numberOfVertices;
-unsigned int posStep;
-unsigned int normStep;
-unsigned int tcStep;
-unsigned int stride;
-float angle=0.0;
-float viewAngle = 0.0;
-
int useTheProgram()
{
const char *vsSource = file2string("tnl.vert");
glBindBuffer(GL_ARRAY_BUFFER, 0);
- eglSwapBuffers(eglDisplay, eglSurface);
+ k_gl_swap_buffers();
angle += .007f;
- return !isEGLError("drawStuff");
+ return 1;
}
void deleteStuff(){
/* ------------------------------------------------------------- */
-#include <X11/Xutil.h>
-
-Window x11Window = 0;
-Display* x11Display = 0;
-long x11Screen = 0;
-XVisualInfo* x11Visual = 0;
-Colormap x11Colormap = 0;
-
-int getX11Display(int windowwidth, int windowheight)
-{
- x11Display = XOpenDisplay(0);
-
- if(!x11Display) {
- printf("Error: Unable to open X display\n");
- return 0;
- }
-
- x11Screen = XDefaultScreen(x11Display);
- Window rootWindow = RootWindow(x11Display, x11Screen);
- int depth = DefaultDepth(x11Display, x11Screen);
- x11Visual = malloc(sizeof(XVisualInfo));
- XMatchVisualInfo(x11Display, x11Screen, depth, TrueColor, x11Visual);
-
- if(!x11Visual) {
- printf("Error: Unable to acquire visual\n");
- return 0;
- }
-
- x11Colormap = XCreateColormap(x11Display, rootWindow, x11Visual->visual, AllocNone);
- XSetWindowAttributes XSWA;
- XSWA.colormap = x11Colormap;
- XSWA.event_mask = StructureNotifyMask | ExposureMask |
- ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask;
- unsigned int cwmask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap;
-
- x11Window = XCreateWindow(x11Display, RootWindow(x11Display, x11Screen), 0, 0, windowwidth, windowheight,
- 0, CopyFromParent, InputOutput, CopyFromParent, cwmask, &XSWA);
- XMapWindow(x11Display, x11Window);
- XFlush(x11Display);
-
- eglX11Display = (EGLNativeDisplayType)x11Display;
- eglX11Window = (EGLNativeWindowType) x11Window;
-
- return 1;
-}
-
-void cleanupX11()
-{
- if(x11Window) XDestroyWindow(x11Display, x11Window);
- if(x11Colormap) XFreeColormap( x11Display, x11Colormap);
- if(x11Display) XCloseDisplay( x11Display);
-}
-
-void forKernel()
-{
- int nm = XPending(x11Display);
- int m;
- for(m=0; m< nm; m++) {
- XEvent event;
- XNextEvent(x11Display, &event);
- switch(event.type){
- case ButtonPress:
- break;
- case KeyPress:
- break;
- default:
- break;
- }
- }
-}
-
-/* ------------------------------------------------------------- */
-