First display with X11 and direct openGl in a display, transparency is OK

This commit is contained in:
Edouard Dupin 2011-10-13 14:17:23 +02:00
commit a98717f6a6
4 changed files with 664 additions and 0 deletions

62
.gitignore vendored Normal file
View File

@ -0,0 +1,62 @@
###################################
# folders
###################################
CVS
.svn
Object/
doxygen/API/
doxygen/ALL/
###################################
# backup files
###################################
*~
*.swp
*.old
*.bck
###################################
# Compiled source #
###################################
*.com
*.class
*.dll
*.exe
*.o
*.so
*.pyc
tags
ewol
out
ewol_debug
ewol_release
###################################
# Packages #
###################################
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
###################################
# Logs and databases #
###################################
*.log
*.sql
*.sqlite
###################################
# OS generated files #
###################################
.DS_Store?
ehthumbs.db
Icon?
Thumbs.db

269
Makefile Normal file
View File

@ -0,0 +1,269 @@
##################################################################################################################
# #
# Fichier : Makefile #
# #
# Type : Makefile d'un programme complet #
# #
# Auteur : Heero Yui #
# #
# Evolutions : Date Auteur Raison #
# 2010-01-29 Heero Yui Mise en place d'un makefile ultra simple #
# 2011-07-14 Heero Yui Rework the current dorder includion (simplification) #
# #
# Notes : This makefile might be edited with an editor compatible with escape char and carrer return #
# char #
# #
# Concu Pour le projet ewol #
# #
##################################################################################################################
export F_GRAS=
export F_INVERSER=
export F_SOUSLIGNER=
export F_NORMALE=
export F_NOIR=
export F_ROUGE=
export F_VERT=
export F_MARRON=
export F_BLUE=
export F_VIOLET=
export F_CYAN=
export F_GRIS=
export CADRE_HAUT_BAS=' $(F_INVERSER) $(F_NORMALE)'
export CADRE_COTERS=' $(F_INVERSER) $(F_NORMALE) $(F_INVERSER) $(F_NORMALE)'
VERSION_TAG=$(shell git describe --tags)
#$(info $(VERSION_TAG))
VERSION_TAG_SHORT=$(shell git describe --tags --abbrev=0)
#$(info $(VERSION_TAG_SHORT))
VERSION_BUILD_TIME=$(shell date)
#$(info $(VERSION_BUILD_TIME))
###############################################################################
### Compilateur base system ###
###############################################################################
CXX=g++
CC=gcc
AR=ar
DEBUG:=1
###############################################################################
### Compilation Define ###
###############################################################################
ifeq ("$(DEBUG)", "0")
DEFINE= -DEDN_DEBUG_LEVEL=1 -DNDEBUG -DVERSION_TAG_NAME="\"$(VERSION_TAG)-release\""
else
DEFINE= -DEDN_DEBUG_LEVEL=3 -DVERSION_TAG_NAME="\"$(VERSION_TAG)-debug\""
endif
DEFINE+= -DVERSION_BUILD_TIME="\"$(VERSION_BUILD_TIME)\""
X11FLAGS= -lX11 -lGL -lGLU -lXrandr
###############################################################################
### Basic Cfags ###
###############################################################################
# basic GTK librairy
CXXFLAGS= $(X11FLAGS)
# Linux thread system
#CXXFLAGS+= -lpthread
# Enable debug (cgdb edn)
CXXFLAGS+= -g -O0
#CXXFLAGS+= -O2
# display all flags
CXXFLAGS+= -Wall
# ...
CXXFLAGS+= -D_REENTRANT
# internal defines
CXXFLAGS+= $(DEFINE)
CFLAGS= $(CXXFLAGS) -std=c99
# basic GTK librairy
LDFLAGS= $(X11FLAGS)
# Linux thread system
#LDFLAGS+= -lpthread
# Dynamic connection of the CALLBACK of the GUI
LDFLAGS+= -Wl,--export-dynamic
###############################################################################
### Project Name ###
###############################################################################
PROG_NAME=ewol
###############################################################################
### Basic Project description Files ###
###############################################################################
FILE_DIRECTORY=Sources
OUTPUT_NAME_RELEASE=$(PROG_NAME)_release
OUTPUT_NAME_DEBUG=$(PROG_NAME)_debug
OBJECT_DIR=Object
ifeq ("$(DEBUG)", "0")
OBJECT_DIRECTORY=$(OBJECT_DIR)/release
OUTPUT_NAME = $(OUTPUT_NAME_RELEASE)
else
OBJECT_DIRECTORY=$(OBJECT_DIR)/debug
OUTPUT_NAME = $(OUTPUT_NAME_DEBUG)
endif
###############################################################################
### Generique dependency ###
###############################################################################
MAKE_DEPENDENCE=Makefile
###############################################################################
### Files Listes ###
###############################################################################
# tiny XML (extern OPEN Sources) :
CXXFILES = Main.cpp
###############################################################################
### Liste of folder where .h can be ###
###############################################################################
LISTE_MODULES = $(dir $(CXXFILES))
INCLUDE_DIRECTORY = $(addprefix -I$(FILE_DIRECTORY)/, $(LISTE_MODULES))
###############################################################################
### Build Object Files List ###
###############################################################################
OBJ = $(addprefix $(OBJECT_DIRECTORY)/, $(CXXFILES:.cpp=.o))
###############################################################################
### Main Part of Makefile ###
###############################################################################
all: build
-include $(OBJ:.o=.d)
build: .encadrer .versionFile $(OUTPUT_NAME)
.encadrer:
@echo $(CADRE_HAUT_BAS)
@echo $(CADRE_COTERS)
@echo ' DEBUT DE COMPILATION DU PROGRAMME :'$(CADRE_COTERS)
@echo ' Repertoire Sources : $(FILE_DIRECTORY)/'$(CADRE_COTERS)
@echo ' Repertoire object : $(OBJECT_DIRECTORY)/'$(CADRE_COTERS)
@echo ' Binaire de sortie : $(F_VIOLET)$(OUTPUT_NAME) $(F_NORMALE)'$(CADRE_COTERS)
@echo $(CADRE_COTERS)
@echo $(CADRE_HAUT_BAS)
@mkdir -p $(addprefix $(OBJECT_DIRECTORY)/, $(LISTE_MODULES))
FILE_IMAGES= data/imagesSources/*.png
.versionFile :
@rm -f $(OBJECT_DIRECTORY)/GuiTools/WindowsManager/WindowsManager.o
# Tool used to create a binary version of every element png or other needed by the application
pngToCpp: tools/pngToCpp/pngToCpp.c
@echo $(F_ROUGE)" (bin) $@"$(F_NORMALE)
@$(CXX) $< -o $@
@strip -s $@
# Generate basic
$(FILE_DIRECTORY)/GuiTools/myImage.cpp: $(FILE_IMAGES) $(MAKE_DEPENDENCE) pngToCpp
@echo $(F_BLUE)" (.cpp) *.png ==> $@"$(F_NORMALE)
@./pngToCpp $@ $(FILE_IMAGES)
# build C++
$(OBJECT_DIRECTORY)/%.o: $(FILE_DIRECTORY)/%.cpp $(MAKE_DEPENDENCE)
@echo $(F_VERT)" (.o) $<"$(F_NORMALE)
@$(CXX) $< -c -o $@ $(INCLUDE_DIRECTORY) $(CXXFLAGS) -MMD
# build binary Release Mode
$(OUTPUT_NAME_RELEASE): $(OBJ) $(MAKE_DEPENDENCE)
@echo $(F_ROUGE)" (bin) $@ "$(F_NORMALE)
@$(CXX) $(OBJ) $(LDFLAGS) -o $@
@cp $@ $(PROG_NAME)
# build binary Debug Mode
$(OUTPUT_NAME_DEBUG): $(OBJ) $(MAKE_DEPENDENCE)
@echo $(F_ROUGE)" (bin) $@ "$(F_NORMALE)
@$(CXX) $(OBJ) $(LDFLAGS) -o $@
@cp $@ $(PROG_NAME)
clean:
@echo $(CADRE_HAUT_BAS)
@echo ' CLEANING : $(F_VIOLET)$(OUTPUT_NAME)$(F_NORMALE)'$(CADRE_COTERS)
@echo $(CADRE_HAUT_BAS)
@echo Remove Folder : $(OBJECT_DIR)
@rm -rf $(OBJECT_DIR)
@echo Remove File : $(PROG_NAME) $(OUTPUT_NAME_DEBUG) $(OUTPUT_NAME_RELEASE)
@rm -f $(PROG_NAME) $(OUTPUT_NAME_DEBUG) $(OUTPUT_NAME_RELEASE)
@echo Remove File : pngToCpp
@rm -f pngToCpp
@echo Remove File : $(FILE_DIRECTORY)/GuiTools/myImage.*
@rm -f $(FILE_DIRECTORY)/GuiTools/myImage.*
@echo Remove doxygen files : doxygen/*
@rm -rf doxygen
@rm -f doxygen.log
@echo Remove temporary files *.bck
@rm -f `find . -name "*.bck"`
count:
wc -l Makefile `find $(FILE_DIRECTORY)/ -name "*.cpp"` `find $(FILE_DIRECTORY)/ -name "*.h"`
install: .encadrer .versionFile $(OUTPUT_NAME_RELEASE)
@echo $(CADRE_HAUT_BAS)
@echo ' INSTALL : $(F_VIOLET)$(OUTPUT_NAME_RELEASE)=>$(PROG_NAME)$(F_NORMALE)'$(CADRE_COTERS)
@echo $(CADRE_HAUT_BAS)
@echo $(F_ROUGE)" (stripped) $(OUTPUT_NAME_RELEASE) => $(PROG_NAME) "$(F_NORMALE)
@cp $(OUTPUT_NAME_RELEASE) $(PROG_NAME)
@strip -s $(PROG_NAME)
@echo $(F_VERT)" (copy) $(PROG_NAME) /usr/bin/ "$(F_NORMALE)
@cp -vf $(PROG_NAME) /usr/bin/
@echo $(F_VERT)" (data) data/* ==> /usr/share/edn/ "$(F_NORMALE)
@mkdir -p /usr/share/edn/
@rm -rf /usr/share/edn/*
@cp -vf data/*.xml /usr/share/edn/
@mkdir -p /usr/share/edn/images/
@cp -vf data/imagesSources/icone.png /usr/share/edn/images/
@cp -vf data/imagesSources/delete-24px.png /usr/share/edn/images/
# http://alp.developpez.com/tutoriels/debian/creer-paquet/
package: .encadrer
@echo 'Create Folders ...'
@mkdir -p package/$(PROG_NAME)/DEBIAN/
@mkdir -p package/$(PROG_NAME)/usr/bin/
@mkdir -p package/$(PROG_NAME)/usr/share/doc/
@mkdir -p package/$(PROG_NAME)/usr/share/edn/
# Create the control file
@echo "Package: "$(PROG_NAME) > package/$(PROG_NAME)/DEBIAN/control
@echo "Version: "$(VERSION_TAG_SHORT) >> package/$(PROG_NAME)/DEBIAN/control
@echo "Section: Development,Editors" >> package/$(PROG_NAME)/DEBIAN/control
@echo "Priority: optional" >>package/$(PROG_NAME)/DEBIAN/control
@echo "Architecture: all" >> package/$(PROG_NAME)/DEBIAN/control
@echo "Depends: bash" >> package/$(PROG_NAME)/DEBIAN/control
@echo "Maintainer: Mr DUPIN Edouard <yui.heero@gmail.com>" >> package/$(PROG_NAME)/DEBIAN/control
@echo "Description: Text editor for sources code with ctags management" >> package/$(PROG_NAME)/DEBIAN/control
@echo "" >> package/$(PROG_NAME)/DEBIAN/control
# Create the PostRm
@echo "#!/bin/bash" > package/$(PROG_NAME)/DEBIAN/postrm
@echo "rm ~/."$(PROG_NAME) >> package/$(PROG_NAME)/DEBIAN/postrm
@echo "" >> package/$(PROG_NAME)/DEBIAN/postrm
# Enable Execution in script
@chmod 755 package/$(PROG_NAME)/DEBIAN/post*
@#chmod 755 package/$(PROG_NAME)/DEBIAN/pre*
# copy licence and information :
@cp README package/$(PROG_NAME)/usr/share/doc/README
@cp licence.txt package/$(PROG_NAME)/usr/share/doc/copyright
@echo "First generation in progress" >> package/$(PROG_NAME)/usr/share/doc/changelog
@cp -vf $(PROG_NAME) package/$(PROG_NAME)/usr/bin/
@cp -vf data/*.xml package/$(PROG_NAME)/usr/share/edn/
@cd package; dpkg-deb --build $(PROG_NAME)

41
README.md Normal file
View File

@ -0,0 +1,41 @@
Edn
====
`Ewol` (Edn Widget OpenGl Layer) is a FREE software.
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
Instructions
============
download the software :
git clone git://github.com/HeeroYui/ewol.git
cd edn
Compile software and install :
sudo make DEBUG=0 install
Run Software :
???
License
=======
You can:
- Redistribute the sources code and binaries.
- Modify the Sources code.
- Use a part of the sources (less than 50%) in an other software, just write somewhere "Edn is great" visible by the user (on your product or on your website with a link to my page).
- Redistribute the modification only if you want.
- Send me the bug-fix (it could be great).
- Pay me a beer or some other things.
- Print the source code on WC paper ...
You can NOT:
- Earn money with this Software (But I can).
- Add malware in the Sources.
- Do something bad with the sources.
- Use it to travel in the space with a toaster.
I reserve the right to change this licence. If it change the version of the copy you have keep its own license

292
Sources/Main.cpp Normal file
View File

@ -0,0 +1,292 @@
/**
*******************************************************************************
* @file Main.cpp
* @brief main fonction
* @author Edouard DUPIN
* @date 13/10/2011
* @par Project
* Edn
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/glx.h>
#include <X11/Xatom.h>
#include <X11/extensions/Xrender.h>
// need to run xcompmgr to have transparency
static Atom del_atom;
static Display *Xdisplay;
static GLXFBConfig fbconfig;
static Window WindowHandle, GLXWindowHandle;
static int width, height;
/**
* @brief
*/
static Bool WaitForMapNotify(Display *d, XEvent *e, char *arg)
{
return (e->type == MapNotify) && (e->xmap.window == *(Window*)arg);
}
/**
* @brief Create the X11 windows
*/
static void createX11Window()
{
XEvent event;
int x,y, attr_mask;
XSizeHints hints;
XWMHints *StartupState;
XTextProperty textprop;
XSetWindowAttributes attr;
static char *title = (char*)"FTB's little OpenGL example";
// Connect to the X server
Xdisplay = XOpenDisplay(NULL);
if (NULL == Xdisplay) {
fprintf(stderr, "Couldn't connect to X server\n");
exit(-1);
}
int Xscreen = DefaultScreen(Xdisplay);
Window Xroot = RootWindow(Xdisplay, Xscreen);
int numfbconfigs;
int VisualData[] = {
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
GLX_DOUBLEBUFFER, True,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_ALPHA_SIZE, 1,
GLX_DEPTH_SIZE, 1,
None
};
XVisualInfo *visual;
GLXFBConfig *fbconfigs = glXChooseFBConfig(Xdisplay, Xscreen, VisualData, &numfbconfigs);
for(int i = 0; i<numfbconfigs; i++) {
visual = glXGetVisualFromFBConfig(Xdisplay, fbconfigs[i]);
if(!visual) {
continue;
}
XRenderPictFormat * pictFormat = XRenderFindVisualFormat(Xdisplay, visual->visual);
if(!pictFormat) {
continue;
}
if(pictFormat->direct.alphaMask > 0) {
fbconfig = fbconfigs[i];
break;
}
}
// Create a colormap - only needed on some X clients, eg. IRIX
attr.colormap = XCreateColormap(Xdisplay, Xroot, visual->visual, AllocNone);;
attr.border_pixel = 0;
attr.event_mask = StructureNotifyMask
| EnterWindowMask
| LeaveWindowMask
| ExposureMask
| ButtonPressMask
| ButtonReleaseMask
| OwnerGrabButtonMask
| KeyPressMask
| KeyReleaseMask;
// set no background at the gui
attr.background_pixmap = None;
// select internal attribute
attr_mask = CWBackPixmap | CWColormap | CWBorderPixel | CWEventMask;
// Create the window
width = DisplayWidth(Xdisplay, DefaultScreen(Xdisplay))/2;
height = DisplayHeight(Xdisplay, DefaultScreen(Xdisplay))/2;
x=width/2;
y=height/4;
// Real create of the window
WindowHandle = XCreateWindow(Xdisplay,
Xroot,
x, y, width, height,
1,
visual->depth,
InputOutput,
visual->visual,
attr_mask, &attr);
if( !WindowHandle ) {
fprintf(stderr, "Couldn't create the window\n");
exit(-1);
}
/* Configure it... (ok, ok, this next bit isn't "minimal") */
textprop.value = (unsigned char*)title;
textprop.encoding = XA_STRING;
textprop.format = 8;
textprop.nitems = strlen(title);
hints.x = x;
hints.y = y;
hints.width = width;
hints.height = height;
hints.flags = USPosition|USSize;
StartupState = XAllocWMHints();
StartupState->initial_state = NormalState;
StartupState->flags = StateHint;
XSetWMProperties(Xdisplay, WindowHandle,&textprop, &textprop,/* Window title/icon title*/
NULL, 0,/* Argv[], argc for program*/
&hints, /* Start position/size*/
StartupState,/* Iconised/not flag */
NULL);
XFree(StartupState);
/* Open it, wait for it to appear */
XMapWindow(Xdisplay, WindowHandle);
XIfEvent(Xdisplay, &event, WaitForMapNotify, (char*)&WindowHandle);
// Set the kill atom so we get a message when the user tries to close the window
if ((del_atom = XInternAtom(Xdisplay, "WM_DELETE_WINDOW", 0)) != None) {
XSetWMProtocols(Xdisplay, WindowHandle, &del_atom, 1);
}
}
/**
* @brief Create a special context to manage transparency of the windows inside X11 system :
*/
static void createTheRenderContext()
{
/* See if we can do OpenGL on this visual */
int dummy;
if (!glXQueryExtension(Xdisplay, &dummy, &dummy)) {
fprintf(stderr, "OpenGL not supported by X server\n");
exit(-1);
}
/* Create the OpenGL rendering context */
GLXContext RenderContext = glXCreateNewContext(Xdisplay, fbconfig, GLX_RGBA_TYPE, 0, True);
if (!RenderContext) {
fprintf(stderr, "Failed to create a GL context\n");
exit(-1);
}
GLXWindowHandle = glXCreateWindow(Xdisplay, fbconfig, WindowHandle, NULL);
/* Make it current */
if (!glXMakeContextCurrent(Xdisplay, GLXWindowHandle, GLXWindowHandle, RenderContext)) {
fprintf(stderr, "glXMakeCurrent failed for window\n");
exit(-1);
}
}
/**
* @brief draw the current diplay of the screen
*/
static void Draw(void)
{
// set the size of the open GL system
glViewport(0,0,width,height);
// Clear the screen with transparency ...
glClearColor(0.750, 0.750, 0.750, 0.5);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0., (float)width, 0., (float)height, 1., 20.);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -5);
glBegin(GL_QUADS);
glColor3f(1., 0., 0.); glVertex3f( .25*(float)width, .25*(float)height, 0.);
glColor3f(0., 1., 0.); glVertex3f( .75*(float)width, .25*(float)height, 0.);
glColor3f(0., 0., 1.); glVertex3f( .75*(float)width, .75*(float)height, 0.);
glColor3f(1., 1., 0.); glVertex3f( .25*(float)width, .75*(float)height, 0.);
glEnd();
printf("redraw (%d,%d)\n", width, height);
/* Swapbuffers */
glXSwapBuffers(Xdisplay, GLXWindowHandle);
}
/**
* @brief main input fonction
*/
int main(int argc, char *argv[])
{
printf("==================================================\n");
printf("== Configuration (Start)\n");
printf("==================================================\n");
createX11Window();
createTheRenderContext();
printf("==================================================\n");
printf("== Configuration (End)\n");
printf("==================================================\n");
printf("==================================================\n");
printf("== Main Process (Start)\n");
printf("==================================================\n");
// main cycle
while(1) {
XEvent event;
XConfigureEvent *xc;
// main X boucle :
while (XPending(Xdisplay)) {
XNextEvent(Xdisplay, &event);
switch (event.type)
{
case ClientMessage:
// Request close of the current client :
if (event.xclient.data.l[0] == del_atom) {
// TODO : Clear all internal elements ...
exit(0);
}
break;
case ConfigureNotify:
xc = &(event.xconfigure);
width = xc->width;
height = xc->height;
break;
}
}
Draw();
usleep( 100000 );
}
return 0;
}