2014-01-17 07:04:33 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
2014-08-09 12:42:56 +02:00
|
|
|
#include <render.h>
|
2014-01-17 07:04:33 +01:00
|
|
|
#include "gbm.h"
|
|
|
|
#include <kos32sys.h>
|
|
|
|
|
2014-01-17 16:35:36 +01:00
|
|
|
|
2014-01-17 07:04:33 +01:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
struct gbm_device *gbm;
|
|
|
|
struct gbm_surface *gs;
|
2014-01-21 09:09:01 +01:00
|
|
|
struct render *render;
|
2014-01-17 07:04:33 +01:00
|
|
|
|
|
|
|
EGLDisplay dpy;
|
|
|
|
EGLint major, minor;
|
|
|
|
|
|
|
|
EGLContext context;
|
|
|
|
EGLSurface surface;
|
2014-01-21 09:09:01 +01:00
|
|
|
|
2014-01-17 07:04:33 +01:00
|
|
|
EGLConfig config;
|
|
|
|
|
|
|
|
EGLint config_attribs[32];
|
|
|
|
EGLint num_configs, i;
|
2014-08-09 12:42:56 +02:00
|
|
|
int width = 400;
|
|
|
|
int height = 300;
|
|
|
|
int skinh;
|
|
|
|
int run =1;
|
2014-01-17 07:04:33 +01:00
|
|
|
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = get_service("DISPLAY");
|
|
|
|
gbm = gbm_create_device(fd);
|
|
|
|
if( gbm == NULL){
|
|
|
|
printf("failed to initialize GBM device");
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
dpy = eglGetDisplay((EGLNativeDisplayType)gbm);
|
|
|
|
|
|
|
|
if (!eglInitialize(dpy, &major, &minor))
|
|
|
|
printf("failed to initialize EGL display");
|
|
|
|
|
|
|
|
printf("EGL_VERSION = %s\n", eglQueryString(dpy, EGL_VERSION));
|
|
|
|
printf("EGL_VENDOR = %s\n", eglQueryString(dpy, EGL_VENDOR));
|
|
|
|
printf("EGL_EXTENSIONS = %s\n", eglQueryString(dpy, EGL_EXTENSIONS));
|
|
|
|
printf("EGL_CLIENT_APIS = %s\n",eglQueryString(dpy, EGL_CLIENT_APIS));
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
config_attribs[i++] = EGL_RED_SIZE;
|
|
|
|
config_attribs[i++] = 1;
|
|
|
|
config_attribs[i++] = EGL_GREEN_SIZE;
|
|
|
|
config_attribs[i++] = 1;
|
|
|
|
config_attribs[i++] = EGL_BLUE_SIZE;
|
|
|
|
config_attribs[i++] = 1;
|
|
|
|
config_attribs[i++] = EGL_DEPTH_SIZE;
|
|
|
|
config_attribs[i++] = 1;
|
|
|
|
|
|
|
|
config_attribs[i++] = EGL_SURFACE_TYPE;
|
|
|
|
config_attribs[i++] = EGL_WINDOW_BIT;
|
|
|
|
|
|
|
|
config_attribs[i++] = EGL_RENDERABLE_TYPE;
|
|
|
|
config_attribs[i++] = EGL_OPENGL_BIT;
|
|
|
|
config_attribs[i] = EGL_NONE;
|
|
|
|
|
|
|
|
if (!eglChooseConfig(dpy,config_attribs, &config, 1, &num_configs) || !num_configs)
|
|
|
|
printf("failed to choose a config");
|
|
|
|
|
|
|
|
eglBindAPI(EGL_OPENGL_API);
|
|
|
|
context = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL);
|
|
|
|
if (!context)
|
|
|
|
printf("failed to create context");
|
|
|
|
|
2014-08-09 12:42:56 +02:00
|
|
|
gs = gbm_surface_create(gbm, width, height, GBM_BO_FORMAT_ARGB8888, GBM_BO_USE_RENDERING);
|
|
|
|
|
|
|
|
skinh = get_skin_height();
|
2014-01-17 07:04:33 +01:00
|
|
|
|
|
|
|
BeginDraw();
|
2014-08-09 12:42:56 +02:00
|
|
|
DrawWindow(20, 20, width+TYPE_3_BORDER_WIDTH*2,
|
|
|
|
height+TYPE_3_BORDER_WIDTH+skinh, "gl-render", 0x000000, 0x74);
|
2014-01-17 07:04:33 +01:00
|
|
|
EndDraw();
|
|
|
|
|
2014-01-20 16:03:51 +01:00
|
|
|
surface = eglCreateWindowSurface(dpy,config, (EGLNativeWindowType)gs, NULL);
|
|
|
|
if (surface == EGL_NO_SURFACE)
|
|
|
|
printf("failed to create surface");
|
2014-01-17 07:04:33 +01:00
|
|
|
|
2014-01-20 16:03:51 +01:00
|
|
|
if (!eglMakeCurrent(dpy, surface, surface, context))
|
2014-01-17 07:04:33 +01:00
|
|
|
printf("failed to make window current");
|
|
|
|
|
2014-01-17 16:35:36 +01:00
|
|
|
|
2014-01-19 18:12:34 +01:00
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
2014-08-09 12:42:56 +02:00
|
|
|
glViewport(0, 0, width, height);
|
2014-01-19 18:12:34 +01:00
|
|
|
|
|
|
|
glClearColor( 0, 0, 0, 1);
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glColor3f(1,0,0);
|
|
|
|
glVertex3f( 0.9, -0.9, -30.0);
|
|
|
|
glColor3f(1,1,0);
|
|
|
|
glVertex3f( 0.9, 0.9, -30.0);
|
|
|
|
|
|
|
|
glColor3f(1,1,1);
|
|
|
|
glVertex3f( 0.1, 0.9, -30.0);
|
|
|
|
glColor3f(1,0,1);
|
|
|
|
glVertex3f( 0.1, -0.9, -30.0);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glFlush();
|
|
|
|
|
2014-08-09 12:42:56 +02:00
|
|
|
// asm volatile ("int3");
|
2014-01-21 09:09:01 +01:00
|
|
|
|
2014-08-09 12:42:56 +02:00
|
|
|
render = create_render(dpy, surface, TYPE_3_BORDER_WIDTH, skinh);
|
|
|
|
render_blit(render, PX_BACK);
|
2014-01-21 09:09:01 +01:00
|
|
|
|
2014-08-09 12:42:56 +02:00
|
|
|
while (run)
|
2014-01-21 09:09:01 +01:00
|
|
|
{
|
2014-08-09 12:42:56 +02:00
|
|
|
oskey_t key;
|
|
|
|
int ev;
|
2014-01-21 09:09:01 +01:00
|
|
|
|
2014-08-09 12:42:56 +02:00
|
|
|
ev = get_os_event();
|
|
|
|
switch(ev)
|
2014-01-21 09:09:01 +01:00
|
|
|
{
|
2014-08-09 12:42:56 +02:00
|
|
|
case 1:
|
|
|
|
BeginDraw();
|
|
|
|
DrawWindow(0,0,0,0,NULL,0,0x74);
|
|
|
|
EndDraw();
|
|
|
|
render_blit(render, PX_BACK);
|
2014-01-21 09:09:01 +01:00
|
|
|
break;
|
|
|
|
|
2014-08-09 12:42:56 +02:00
|
|
|
case 2:
|
|
|
|
key = get_key();
|
|
|
|
if (key.code == 27)
|
|
|
|
run = 0;
|
|
|
|
break;
|
2014-01-21 09:09:01 +01:00
|
|
|
|
2014-08-09 12:42:56 +02:00
|
|
|
case 3:
|
|
|
|
if(get_os_button()==1)
|
|
|
|
run = 0;
|
|
|
|
break;
|
|
|
|
};
|
2014-01-21 09:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-09 12:42:56 +02:00
|
|
|
glFinish();
|
|
|
|
eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
// eglDestroySurface(dpy, surface);
|
|
|
|
// gbm_surface_destroy(gs);
|
|
|
|
eglDestroyContext(dpy, context);
|
|
|
|
eglTerminate(dpy);
|
2014-01-19 18:12:34 +01:00
|
|
|
|
2014-08-09 12:42:56 +02:00
|
|
|
return 0;
|
2014-01-19 18:12:34 +01:00
|
|
|
}
|
|
|
|
|
2014-08-09 12:42:56 +02:00
|
|
|
|
2014-01-21 09:09:01 +01:00
|
|
|
#if 0
|
2014-01-19 18:12:34 +01:00
|
|
|
GLuint create_framebuffer(int width, int height, GLuint *tex)
|
|
|
|
{
|
|
|
|
GLuint buffer;
|
|
|
|
|
|
|
|
glGenTextures(1, tex);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, *tex);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
|
|
|
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
|
|
|
|
GL_UNSIGNED_BYTE, NULL);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
|
|
|
|
glGenFramebuffers(1, &buffer);
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, buffer);
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER,
|
|
|
|
GL_COLOR_ATTACHMENT0,
|
|
|
|
GL_TEXTURE_2D, *tex,0);
|
|
|
|
return buffer;
|
|
|
|
}
|
2014-01-21 09:09:01 +01:00
|
|
|
#endif
|