[DEV] coret display of the basic sample ==> now need to normalize

This commit is contained in:
Edouard DUPIN 2015-07-17 21:01:55 +02:00
parent 3a89eaab79
commit 9ae89a2e4e
10 changed files with 160 additions and 27 deletions

View File

@ -90,11 +90,13 @@ void gale::Application::onResize(const vec2& _size) {
}
void gale::Application::setSize(const vec2& _size) {
gale::Context& context = gale::getContext();
context.setSize(_size);
}
vec2 gale::Application::getSize() const {
return vec2(0,0);
gale::Context& context = gale::getContext();
return context.getSize();
}
void gale::Application::onMovePosition(const vec2& _size) {

View File

@ -618,7 +618,10 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) {
if( true == needRedraw
|| true == _displayEveryTime) {
m_FpsSystem.incrementCounter();
// set the curent interface :
lockContext();
m_application->onDraw(*this);
unLockContext();
hasDisplayDone = true;
}
}

View File

@ -146,6 +146,20 @@ void gale::openGL::swap() {
}
void gale::openGL::clearColor(const etk::Color<float>& _color) {
glClearColor(_color.r(), _color.g(), _color.b(), _color.a());
}
void gale::openGL::clearDepth(float _value) {
glClearDepth(_value);
}
void gale::openGL::clearStencil(int32_t _value) {
glClearStencil(_value);
}
void gale::openGL::clear(uint32_t _flags) {
glClear(_flags);
}
std::ostream& gale::operator <<(std::ostream& _os, const enum openGL::openGlFlags& _obj) {
static std::vector<std::pair<enum openGL::openGlFlags, const char*>> list = {
@ -197,16 +211,16 @@ std::ostream& gale::operator <<(std::ostream& _os, const enum openGL::openGlFlag
std::vector<std::pair<enum gale::openGL::renderMode, std::string>>& getListRenderMode() {
static std::vector<std::pair<enum gale::openGL::renderMode, std::string>> list = {
std::make_pair(gale::openGL::renderPoint, "POINTS"),
std::make_pair(gale::openGL::renderLine, "LINES"),
std::make_pair(gale::openGL::renderLineStrip, "LINES_STRIP"),
std::make_pair(gale::openGL::renderLineLoop, "LINE_LOOP"),
std::make_pair(gale::openGL::renderTriangle, "TRIANGLE"),
std::make_pair(gale::openGL::renderTriangleStrip, "TRIANGLE_STRIP"),
std::make_pair(gale::openGL::renderTriangleFan, "TRIANGLE_FAN"),
std::make_pair(gale::openGL::renderQuad, "QUAD"),
std::make_pair(gale::openGL::renderQuadStrip, "QUAD_STRIP"),
std::make_pair(gale::openGL::renderPolygon, "POLYGON"),
std::make_pair(gale::openGL::render_point, "POINTS"),
std::make_pair(gale::openGL::render_line, "LINES"),
std::make_pair(gale::openGL::render_lineStrip, "LINES_STRIP"),
std::make_pair(gale::openGL::render_lineLoop, "LINE_LOOP"),
std::make_pair(gale::openGL::render_triangle, "TRIANGLE"),
std::make_pair(gale::openGL::render_triangleStrip, "TRIANGLE_STRIP"),
std::make_pair(gale::openGL::render_triangleFan, "TRIANGLE_FAN"),
std::make_pair(gale::openGL::render_quad, "QUAD"),
std::make_pair(gale::openGL::render_quadStrip, "QUAD_STRIP"),
std::make_pair(gale::openGL::render_polygon, "POLYGON"),
};
return list;
}
@ -233,7 +247,7 @@ namespace etk {
}
}
GALE_WARNING("Can not parse : '" << _value << "' set Triangle default value");
_variableRet = gale::openGL::renderTriangle;
_variableRet = gale::openGL::render_triangle;
return false;
}
template<> bool from_string<gale::openGL::renderMode>(gale::openGL::renderMode& _variableRet, const std::u32string& _value) {

View File

@ -12,6 +12,7 @@
#include <etk/types.h>
#include <vector>
#include <etk/math/Matrix4.h>
#include <etk/Color.h>
#ifdef __cplusplus
extern "C" {
@ -110,6 +111,34 @@ namespace gale {
*/
void swap();
/**
* @brief Specifies the clear color value When clear is requested
* @param[in] _value to set [0..1]
*/
void clearColor(const etk::Color<float>& _color);
/**
* @brief Specifies the depth value used when the depth buffer is cleared. The initial value is 1.
* @param[in] _value to set [0..1]
*/
void clearDepth(float _value);
/**
* @brief Specifies the index used by clear to clear the stencil buffer. s is masked with 2 m - 1 , where m is the number of bits in the stencil buffer.
* @param[in] _value
*/
void clearStencil(int32_t _value);
enum clearFlag {
clearFlag_colorBuffer = GL_COLOR_BUFFER_BIT, //!< Indicates the buffers currently enabled for color writing.
clearFlag_depthBuffer = GL_DEPTH_BUFFER_BIT, //!< Indicates the depth buffer.
clearFlag_stencilBuffer = GL_STENCIL_BUFFER_BIT //!< Indicates the stencil buffer.
};
/**
* @brief clear sets the bitplane area of the window to values previously selected by clearColor, clearDepth, and clearStencil. Multiple color buffers can be cleared simultaneously by selecting more than one buffer at a time using drawBuffer.
* The pixel ownership test, the scissor test, dithering, and the buffer writemasks affect the operation of clear. The scissor box bounds the cleared region. Alpha function, blend function, logical operation, stenciling, texture mapping, and depth-buffering are ignored by clear.
* @param[in] _flags This is the bitwise OR of several values indicating which buffer is to be cleared.
*/
void clear(uint32_t _flags);
enum openGlFlags {
FLAG_BLEND = 1<<0, //!< If enabled, blend the computed fragment color values with the values in the color buffers. See glBlendFunc.
FLAG_CLIP_DISTANCE_I = 1<<1, //!< If enabled, clip geometry against user-defined half space i.
@ -142,17 +171,17 @@ namespace gale {
FLAG_FOG = 1<<28, //!<
};
enum renderMode {
renderPoint = GL_POINTS,
renderLine = GL_LINES,
renderLineStrip = GL_LINE_STRIP, //!< Not supported in GALE (TODO : Later)
renderLineLoop = GL_LINE_LOOP,
renderTriangle = GL_TRIANGLES,
renderTriangleStrip = GL_TRIANGLE_STRIP, //!< Not supported in GALE (TODO : Later)
renderTriangleFan = GL_TRIANGLE_FAN, //!< Not supported in GALE (TODO : Later)
render_point = GL_POINTS,
render_line = GL_LINES,
render_lineStrip = GL_LINE_STRIP, //!< Not supported in GALE (TODO : Later)
render_lineLoop = GL_LINE_LOOP,
render_triangle = GL_TRIANGLES,
render_triangleStrip = GL_TRIANGLE_STRIP, //!< Not supported in GALE (TODO : Later)
render_triangleFan = GL_TRIANGLE_FAN, //!< Not supported in GALE (TODO : Later)
#if (!defined(__TARGET_OS__IOs) && !defined(__TARGET_OS__Android))
renderQuad = GL_QUADS, //!< Not supported in OpenGL-ES2
renderQuadStrip = GL_QUAD_STRIP, //!< Not supported in OpenGL-ES2
renderPolygon = GL_POLYGON //!< Not supported in OpenGL-ES2
render_quad = GL_QUADS, //!< Not supported in OpenGL-ES2
render_quadStrip = GL_QUAD_STRIP, //!< Not supported in OpenGL-ES2
render_polygon = GL_POLYGON //!< Not supported in OpenGL-ES2
#else
renderQuad, //!< Not supported in OpenGL-ES2
renderQuadStrip, //!< Not supported in OpenGL-ES2

View File

@ -86,7 +86,8 @@ def create(target):
'gale/resource/Program.cpp',
'gale/resource/Resource.cpp',
'gale/resource/Shader.cpp',
'gale/resource/Texture.cpp'
'gale/resource/Texture.cpp',
'gale/resource/VirtualBufferObject.cpp'
])
# name of the dependency

View File

@ -13,21 +13,75 @@
#include <gale/Application.h>
#include <gale/context/Context.h>
#include <gale/resource/Program.h>
class MainApplication : public gale::Application {
private:
std::shared_ptr<gale::resource::Program> m_GLprogram;
int32_t m_GLPosition;
int32_t m_GLMatrix;
int32_t m_GLColor;
public:
void onCreate(gale::Context& _context) {
setSize(vec2(800, 600));
m_GLprogram = gale::resource::Program::create("DATA:basic.prog");
if (m_GLprogram != nullptr) {
m_GLPosition = m_GLprogram->getAttribute("EW_coord3d");
m_GLColor = m_GLprogram->getAttribute("EW_color");
m_GLMatrix = m_GLprogram->getUniform("EW_MatrixTransformation");
}
std::cout << "==> Init APPL (END)" << std::endl;
}
void onDraw(gale::Context& _context) {
std::cout << "Draw (start)" << std::endl;
ivec2 size = getSize();
// set the basic openGL view port: (position drawed in the windows)
glViewport(0,0,size.x(),size.y());
// Clear all the stacked matrix ...
gale::openGL::setBasicMatrix(mat4());
// clear background
gale::openGL::clearColor(etk::color::yellow);
// real clear request:
gale::openGL::clear(gale::openGL::clearFlag_colorBuffer);
// create a local matrix environnement.
gale::openGL::push();
std::cout << "Draw (end)" << std::endl;
mat4 tmpProjection = etk::matOrtho(-1, 1,
-1, 1,
-2, 2);
// set internal matrix system:
gale::openGL::setMatrix(tmpProjection);
vec3 vertices[3]={ vec3(-0.5,-0.5,0),
vec3(0,0.5,0),
vec3(0.5,-0.5,0)
};
etk::Color<float> color[3] = { etk::color::red,
etk::color::green,
etk::color::blue
};
if (m_GLprogram == nullptr) {
std::cout << "No shader ..." << std::endl;
return;
}
//EWOL_DEBUG(" display " << m_coord.size() << " elements" );
m_GLprogram->use();
// set Matrix : translation/positionMatrix
mat4 projMatrix = gale::openGL::getMatrix();
mat4 camMatrix = gale::openGL::getCameraMatrix();
mat4 tmpMatrix = projMatrix * camMatrix;
m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix);
// position :
m_GLprogram->sendAttribute(m_GLPosition, 3/*x,y,z,unused*/, vertices, 4*sizeof(float));
// color :
m_GLprogram->sendAttribute(m_GLColor, 4/*r,g,b,a*/, color, 4*sizeof(float));
// Request the draw od the elements :
gale::openGL::drawArrays(GL_TRIANGLES, 0, 3 /*number of points*/);
m_GLprogram->unUse();
// Restore context of matrix
gale::openGL::pop();
}
};
/**
* @brief Main of the program (This can be set in every case, but it is not used in Andoid...).
* @param std IO

11
sample/basic.frag Normal file
View File

@ -0,0 +1,11 @@
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
// output :
varying vec4 f_color;
void main(void) {
gl_FragColor = f_color;
}

17
sample/basic.vert Normal file
View File

@ -0,0 +1,17 @@
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
// Input :
attribute vec3 EW_coord3d;
attribute vec4 EW_color;
uniform mat4 EW_MatrixTransformation;
// output :
varying vec4 f_color;
void main(void) {
gl_Position = EW_MatrixTransformation * vec4(EW_coord3d, 1.0);
f_color = EW_color;
}

View File

@ -13,6 +13,8 @@ def create(target):
])
# add dependency of gale
myModule.add_module_depend(['gale'])
myModule.copy_file('basic.frag')
myModule.copy_file('basic.vert')
return myModule

Binary file not shown.