void VideoManager::setVideoDefaults() { glViewport(0, 0, (GLsizei) size.getX(), (GLsizei) size.getY()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, (GLfloat) size.getX(), (GLfloat) size.getY(), 0.0f, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); setClearColor(Color(1.0f, 1.0f, 1.0f)); setColor(Color(0.0f, 0.0f, 0.0f)); glLineWidth(1.5f); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); new Kernel; // will be deleted by the QQmlEngine qmlRegisterSingletonType<Kernel>("Lemonade", 1, 0, "Kernel", kernelInstanceProvider); QQmlEngine engine; auto window_color = app.palette().color(QPalette::Window); QMainWindow window; window.setWindowTitle(window.tr("Lemonade")); window.setMenuBar(initMenuBar()); auto central = new QWidget; auto layout = new QHBoxLayout; layout->setSpacing(0); layout->setContentsMargins(0, 0, 0, 0); auto tool_button_bar = new QQuickWidget(&engine, central); tool_button_bar->setClearColor(window_color); tool_button_bar->setSource( QUrl(QLatin1String("qrc:/content/ToolButtonBar.qml"))); layout->addWidget(tool_button_bar); auto hsplitter = new QSplitter(Qt::Horizontal); hsplitter->setChildrenCollapsible(false); hsplitter->addWidget(initCanvasView()); layout->addWidget(hsplitter); auto vsplitter = new QSplitter(Qt::Vertical); vsplitter->addWidget(initNavigatorPanel()); vsplitter->addWidget(initLayerTreePanel()); hsplitter->addWidget(vsplitter); central->setLayout(layout); window.setCentralWidget(central); window.resize(800, 600); window.show(); return app.exec(); }
void StateManagerGL::setClearState(const gl::State &state, GLbitfield mask) { // Only apply the state required to do a clear setScissor(state.getScissor()); setViewport(state.getViewport()); if ((mask & GL_COLOR_BUFFER_BIT) != 0) { setClearColor(state.getColorClearValue()); const gl::BlendState &blendState = state.getBlendState(); setColorMask(blendState.colorMaskRed, blendState.colorMaskGreen, blendState.colorMaskBlue, blendState.colorMaskAlpha); } if ((mask & GL_DEPTH_BUFFER_BIT) != 0) { setClearDepth(state.getDepthClearValue()); setDepthMask(state.getDepthStencilState().depthMask); } if ((mask & GL_STENCIL_BUFFER_BIT) != 0) { setClearStencil(state.getStencilClearValue()); setStencilMask(state.getDepthStencilState().stencilMask); } }
Render::Render(DriverType driver) : m_driver (driver), m_deferredVBUnlock (true) { m_pixelCenterOffset = 0; setAmbientColor(Colour(0.25f,0.25f,0.25f,1)); setClearColor(Colour(0.52f,0.6f,0.7f,1)); strncpy_s(m_deviceName, sizeof(m_deviceName), "UNKNOWN", sizeof(m_deviceName)); }
bool Graphics::init() { GLenum initResult = glewInit(); if (initResult != GLEW_OK) { return false; } glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); setClearColor(0.1f, 0.5f, 0.95f, 1.0f); return true; }
void ProcessorList::newOpenGLContextCreated() { setUp2DCanvas(); activateAntiAliasing(); setClearColor(black); resized(); }
std::shared_ptr<CameraPerspective> Scene::createPerspectiveCamera(GameObject *cameraObject){ if (!cameraObject ){ cameraObject = createGameObject("PerspectiveCamera"); } auto cam = cameraObject->addComponent<CameraPerspective>(); cam->setNear(0.1f); cam->setFar(100); cam->setFieldOfViewY(glm::radians(60.0f)); cam->setClearColor(glm::vec4(0,0,0,1)); return cam; }
void EditorViewportButton::newOpenGLContextCreated() { setUp2DCanvas(); activateAntiAliasing(); setClearColor(darkgrey); //glClearColor(0.23f, 0.23f, 0.23f, 1.0f); }
// RenderTextureTest RenderTextureTargetNode::RenderTextureTargetNode() { /* * 1 2 * A: A1 A2 * * B: B1 B2 * * A1: premulti sprite * A2: premulti render * * B1: non-premulti sprite * B2: non-premulti render */ auto background = LayerColor::create(Color4B(40,40,40,255)); addChild(background); // sprite 1 sprite1 = Sprite::create("Images/fire.png"); // sprite 2 sprite2 = Sprite::create("Images/fire_rgba8888.pvr"); auto s = Director::getInstance()->getWinSize(); /* Create the render texture */ auto renderTexture = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA4444); this->renderTexture = renderTexture; renderTexture->setPosition(Point(s.width/2, s.height/2)); // [renderTexture setPosition:Point(s.width, s.height)]; // renderTexture.scale = 2; /* add the sprites to the render texture */ renderTexture->addChild(sprite1); renderTexture->addChild(sprite2); renderTexture->setClearColor(Color4F(0, 0, 0, 0)); renderTexture->setClearFlags(GL_COLOR_BUFFER_BIT); /* add the render texture to the scene */ addChild(renderTexture); renderTexture->setAutoDraw(true); scheduleUpdate(); // Toggle clear on / off auto item = MenuItemFont::create("Clear On/Off", CC_CALLBACK_1(RenderTextureTargetNode::touched, this)); auto menu = Menu::create(item, NULL); addChild(menu); menu->setPosition(Point(s.width/2, s.height/2)); }
/**************************************************************************** ** ** Copyright (C) 2015 ** ** This file is generated by the Magus toolkit ** ** 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 ** OWNER 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." ** ****************************************************************************/ #include <QtWidgets> #include <QtOpenGL> #include <QMessageBox> #include "tool_glspherewidget.h" namespace Magus { //****************************************************************************/ QtGLSphereWidget::QtGLSphereWidget(QWidget *parent, QGLWidget *shareWidget) : QGLWidget(parent, shareWidget) { clearColor = Qt::black; xRot = 0; yRot = 0; zRot = 0; program = 0; } //****************************************************************************/ QtGLSphereWidget::~QtGLSphereWidget() { } //****************************************************************************/ QSize QtGLSphereWidget::minimumSizeHint() const { return QSize(16, 16); } //****************************************************************************/ QSize QtGLSphereWidget::sizeHint() const { return QSize(200, 200); } //****************************************************************************/ void QtGLSphereWidget::rotateBy(int xAngle, int yAngle, int zAngle) { xRot += xAngle; yRot += yAngle; zRot += zAngle; updateGL(); } //****************************************************************************/ void QtGLSphereWidget::setClearColor(const QColor &color) { clearColor = color; updateGL(); } //****************************************************************************/ void QtGLSphereWidget::setPixmap(const QPixmap& pixmap, const QString& fullName, const QString& baseName) { mPixmap = pixmap; mFullName = fullName; mBaseName = baseName; } //****************************************************************************/ const QString& QtGLSphereWidget::getFullName(void) const { return mFullName; } //****************************************************************************/ const QString& QtGLSphereWidget::getBaseName(void) const { return mBaseName; } //****************************************************************************/ void QtGLSphereWidget::initializeGL() { initializeOpenGLFunctions(); buildSphere(); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); #ifdef GL_TEXTURE_2D glEnable(GL_TEXTURE_2D); #endif #define PROGRAM_VERTEX_ATTRIBUTE 0 #define PROGRAM_TEXCOORD_ATTRIBUTE 1 QGLShader *vshader = new QGLShader(QGLShader::Vertex, this); const char *vsrc = "attribute highp vec4 vertex;\n" "attribute mediump vec4 texCoord;\n" "varying mediump vec4 texc;\n" "uniform mediump mat4 matrix;\n" "void main(void)\n" "{\n" " gl_Position = matrix * vertex;\n" " texc = texCoord;\n" "}\n"; vshader->compileSourceCode(vsrc); QGLShader *fshader = new QGLShader(QGLShader::Fragment, this); const char *fsrc = "uniform sampler2D texture;\n" "varying mediump vec4 texc;\n" "void main(void)\n" "{\n" " gl_FragColor = texture2D(texture, texc.st);\n" "}\n"; fshader->compileSourceCode(fsrc); program = new QGLShaderProgram(this); program->addShader(vshader); program->addShader(fshader); program->bindAttributeLocation("vertex", PROGRAM_VERTEX_ATTRIBUTE); program->bindAttributeLocation("texCoord", PROGRAM_TEXCOORD_ATTRIBUTE); program->link(); program->bind(); program->setUniformValue("texture", 0); // Set the clear color and rotate the sphere QColor clearColor; clearColor = Qt::black; setClearColor(clearColor); rotateBy(0 * 16, -90 * 16, 180 * 16); }
void CameraFrameBufferTest::onEnter() { auto sizeInpixels = Director::getInstance()->getWinSizeInPixels(); auto size = Director::getInstance()->getWinSize(); auto fboSize = Size(sizeInpixels.width * 1, sizeInpixels.height * 1.5); auto fbo = experimental::FrameBuffer::create(1, fboSize.width, fboSize.height); CameraBaseTest::onEnter(); //auto sprite = Sprite::createWithTexture(fbo); //sprite->setPosition(Vec2(100,100)); //std::string filename = "Sprite3DTest/girl.c3b"; //auto sprite = Sprite3D::create(filename); //sprite->setScale(1.0); //auto animation = Animation3D::create(filename); //if (animation) //{ // auto animate = Animate3D::create(animation); // sprite->runAction(RepeatForever::create(animate)); //} //sprite->setPosition(Vec2(100,100)); auto rt = experimental::RenderTarget::create(fboSize.width, fboSize.height); auto rtDS = experimental::RenderTargetDepthStencil::create(fboSize.width, fboSize.height); fbo->attachRenderTarget(rt); fbo->attachDepthStencilTarget(rtDS); auto sprite = Sprite::createWithTexture(fbo->getRenderTarget()->getTexture()); sprite->setScale(0.3); sprite->runAction(RepeatForever::create(RotateBy::create(1, 90))); sprite->setPosition(size.width/2, size.height/2); addChild(sprite); auto sprite2 = Sprite::create(s_pathGrossini); sprite2->setPosition(Vec2(size.width/5,size.height/5)); addChild(sprite2); sprite2->setCameraMask((unsigned short)CameraFlag::USER1); auto move = MoveBy::create(1.0, Vec2(100,100)); sprite2->runAction( RepeatForever::create( Sequence::createWithTwoActions( move, move->reverse()) ) ); auto camera = Camera::create(); camera->setCameraFlag(CameraFlag::USER1); camera->setDepth(-1); camera->setFrameBufferObject(fbo); fbo->setClearColor(Color4F(1,1,1,1)); addChild(camera); }
void IContext::set( VGuint type, const VGfloat * fv ) { switch ( type ) { case VG_CLEAR_COLOR: setClearColor( fv ); break; case VG_GLYPH_ORIGIN: setGlyphOrigin( fv ); break; default: SetError( VG_ILLEGAL_ARGUMENT_ERROR ); break; } }
std::shared_ptr<CameraOrthographic> Scene::createOrthographicCamera(GameObject *cameraObject) { if (!cameraObject ) { cameraObject = createGameObject("OrthographicCamera"); } auto cam = cameraObject->addComponent<CameraOrthographic>(); glm::ivec2 dim = Engine::context()->getContextSurfaceDim(); cam->setNear(-10); cam->setFar(10); cam->setLeft(-dim.x/2); cam->setRight(dim.x/2); cam->setBottom(-dim.y/2); cam->setTop(dim.y/2); cam->setClearColor(glm::vec4(0,0,0,1)); return cam; }
bool Render_SW_SDL::init() { //Initialize clear color setClearColor( 0.f, 0.f, 0.f, 1.f ); //Create renderer for window m_gRenderer = SDL_CreateRenderer( PGE_Window::window, -1, SDL_RENDERER_SOFTWARE ); if(!m_gRenderer) { LogWarning(QString("SW SDL: Failed to initialize screen surface! ") + SDL_GetError()); return false; } SDL_SetRenderDrawBlendMode(m_gRenderer, SDL_BLENDMODE_BLEND); return true; }
void RenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags) { setClearColor(Color4F(r, g, b, a)); setClearDepth(depthValue); setClearStencil(stencilValue); setClearFlags(flags); this->begin(); //clear screen _beginWithClearCommand.init(_globalZOrder); _beginWithClearCommand.func = CC_CALLBACK_0(RenderTexture::onClear, this); Director::getInstance()->getRenderer()->addCommand(&_beginWithClearCommand); }
void GraphicEngine::initGL() { // Light init if (game->config->getInt("lighting")) glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); glEnable(GL_TEXTURE_2D); setAmbient(MGColor(0.5f, 0.5f, 0.5f, 1.0f)); setClearColor(MGColor(0.0f, 0.0f, 0.0f, 1.0f)); //glPolygonMode(GL_FRONT, GL_LINE); //glPolygonMode(GL_BACK, GL_LINE); glShadeModel (GL_SMOOTH); // ћетод закраски: —√Ћј∆≈Ќџ… glEnable (GL_DEPTH_TEST); // ¬ключаем тест глубины // ¬ Ћ. ј¬“ќћј“»„≈— »… ѕ≈–≈—„≈“ Ќќ–ћјЋ≈… //glEnable (GL_AUTO_NORMAL); glEnable (GL_NORMALIZE); // ¬ Ћ. ќ“—≈„≈Ќ»≈ «јƒЌ»’ √–јЌ≈… glEnable (GL_CULL_FACE); // ¬ключаем отсечение граней glCullFace (GL_BACK); // ”казываем, что отсекать будем задние грани updateScreenSize(); // Init fonts glEnable(GL_BLEND); setBlendFunc(getDefaultBlendFuncS(), getDefaultBlendFuncD()); standart14Normal = FontCache::getInstance()->load("standart_14_normal"); console8Normal = FontCache::getInstance()->load("console_8_normal"); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); GLenum err = glGetError (); if (GL_NO_ERROR != err) Log::error("GraphicEngine::initGL(): OpenGL Error: %s", gluErrorString (err)); Log::info("OpenGL initialized"); }
QIrrlichtWidget::QIrrlichtWidget(QWidget *parent, irr::video::E_DRIVER_TYPE driverType) : QWidget(parent) { qDebug() << "QIrrlichtWidget::ctor()"; setAttribute(Qt::WA_PaintOnScreen, true); setAttribute(Qt::WA_OpaquePaintEvent, true); setMouseTracking(true); setFocusPolicy(Qt::ClickFocus); setFocus(Qt::OtherFocusReason); m_IrrDevice = 0; m_DriverType = driverType; setClearColor(irr::video::SColorf(0.2f, 0.2f, 0.2f)); mousePressed = false; mouseListener = 0; }
void ContextWindow::InitOpenGL() { int PixelFormat; m_hDC = GetDC(m_hWnd); PIXELFORMATDESCRIPTOR pfd; pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.iLayerType = PFD_MAIN_PLANE; pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER; pfd.cDepthBits = 32; pfd.cColorBits = 24; pfd.iPixelType = PFD_TYPE_RGBA; PixelFormat = ChoosePixelFormat(m_hDC, &pfd); if (!SetPixelFormat(m_hDC, PixelFormat, &pfd)) { LOG("Erro ao criar context pixel descriptor."); } m_hRC = wglCreateContext(m_hDC); // Create the context auto a = wglMakeCurrent(m_hDC, m_hRC); // Make the context current auto x = GetLastError(); glewExperimental = true; GLenum err = glewInit(); if (err != GLEW_OK) { LOG("Erro ao inicializar GLEW!"); } setClearColor(glm::vec4(1, 1, 1, 1)); glClearColor(m_ClearColor.r, m_ClearColor.g, m_ClearColor.b, m_ClearColor.a); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); linked::Window::linkedWindowInit(); }
//----------------------------------------------------------------------------- //* Initialize //! Initializes OpenGL. // //! @param fullscreen will render scene in fullscreen if true //! @param width width of window or width of screen resolution //! @param height height of window or height of screen resolution //! @param bitDepth bitDepth to use //! @param refreshRate refresh frequency to use //! @param vSync limits frame rate to the monitor's refresh frequency //! @param hideCursor hides mouse coursor if true //----------------------------------------------------------------------------- bool OpenGLManager::initialize(bool fullscreen, int width, int height, int bitDepth, int refreshRate, bool vSync, bool hideCursor) { m_width = width; m_height = height; m_bitDepth = bitDepth; m_refreshRate = refreshRate; m_fullscreen = fullscreen; m_renderingCallback = NULL; //Set OpenGL Settings setClearColor(0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); //Set render states setCullMode(false, true); setTextureing2D(false); setLighting(false); return true; }
bool ResizeAwareQuickWidget::setupQmlSource(const QUrl &url) { setSource(url); // Set the pixels in the corners to the MainWindow's background color. // FIXME/TODO: too bad that this doesn't really work when that color // happens to be a gradient, like in Linux' KDE5... QPalette myPalette = QApplication::palette(this); QColor myBackgroundColor = myPalette.color(QPalette::Window); setClearColor(myBackgroundColor); if (status() == QQuickWidget::Error) return false; theGameViewPtr = qobject_cast<ViewWorldItem*>(rootObject()->findChild<QQuickItem*>("gameView")); assert(nullptr != theGameViewPtr); if (nullptr == theGameViewPtr) { return false; } connect(theGameViewPtr, SIGNAL(dimensionsChanged(qreal, qreal)), this, SLOT(updateWorldSize(qreal,qreal))); return true; }
void VideoManager::invert() { Color tmp = color; setColor(clearColor); setClearColor(tmp); }
int main(int argc, char **argv) { SDL_Window *win; SDL_Renderer *g; int win_width = 1152, win_height = 720; int flag_forceinwin = 1, dtime = 1000; struct color *renderColor = &GHETTO_WHITE; struct color *backgroundColor = &GHETTO_BLACK; // dem args int c; while ((c = getopt(argc, argv, "t:yh")) != -1) { switch (c) { case 't': // reset delay time dtime = atoi(optarg); printf("Delay time set to: %ims\n", dtime); break; case 'y': // yolo mode flag_forceinwin = 0; printf("YOLO mode intiated\n"); break; case 'h': printHelp(argv[0]); return 0; default: break; } } // seed dat RNG srand((unsigned int) time(NULL)); initSDL(); // grab a window and a renderer win = getWindow(win_width, win_height); g = getRenderer(win); // clear screen setClearColor(backgroundColor); clearScreen(g); // blue lines (for now) setColor(g, renderColor); // line number; used to decide direction // start at 1 int lineNo = 1; // necesary line node structures for linked list: // root line node in list struct node *root = malloc(sizeof(struct node)); // previously generated line node struct node *previous; // line node undergoing generation struct node *current; // first line, start at middle, rand length, go from there struct line *firstLine = genNextLine(NULL, lineNo); // move line to center (genNextLine starts at (0, 0) when // previous is NULL) translateLine(firstLine, win_width / 2, win_height / 2); root->line = firstLine; root->next = current; previous = root; clearScreen(g); drawLine(g, root->line); render(g); // increment line count so loop starts on horizonal lineNo++; delay(dtime); while (1) { if (!handleEvents()) break; // allocate memory for new node current = malloc(sizeof(struct node)); // add to linked list; // new is old's next previous->next = current; if (flag_forceinwin) { // keep line bound to window bounds while (1) { current->line = genNextLine(previous->line, lineNo); if (current->line->x2 > win_width || current->line->y2 > win_height) free(current->line); else break; } } else { // line can do whatever tf it wants current->line = genNextLine(previous->line, lineNo); } // THIS is very necessary; // in rendering: // iterate through linked list until next is NULL // if you don't set new next to null, it thinks theres another // value (will be reset to next element in next iteration of loop) current->next = NULL; clearScreen(g); drawAllLines(g, root); render(g); previous = current; lineNo++; // break up sleeping into smaller segments // to allow user to exit faster int i; for (i = 0; i < 10; i++) { if (!handleEvents()) break; delay(dtime / 10); } if (i < 10) break; } freeLineList(root); cleanup(g, win); return 0; }
void RenderToTextureTest::Init() { camera->setDepthField(10, 1320); camera->setView(Vec3(0, -340, 57), Vec3(0, 30, 20), Vec3(0, 0, 1)); camera->setQueueCullFunc([](int queue) { if (queue == 50) { return true; } return false; }); renderManager = &(SceneManager::instance().getRenderManager()); renderer = &(renderManager->getRenderer()); TextureParser::instance().addTextures("Textures/NormalMap", "png|jpg"); auto texture = TextureManager::instance().getTexture("diffuse"); GeometryPtr geometry = nullptr; MeshPtr mesh = nullptr; geometry = ShapeGenerater::instance().CreateCylinder(50, 50, 100, 10, 10); cylinderNode = CreateMeshEntity(); SetMeshData(cylinderNode, geometry, texture); cylinderNode->getComponent<RenderElement>()->getMaterial()->setQueueID(52); rootNode->addChild(cylinderNode->getNode()); // create a render target renderTarget = Create<RenderTarget>(); renderTarget->setHasDepthBuffer(true); renderTarget->setHasStencilBuffer(false); renderer->setupRenderTarget(*renderTarget); auto size = renderTarget->getSize(); auto presCamera = CreateNode<Camera>(); presCamera->setViewport(size.width, size.height); presCamera->setDepthField(10, 1320); presCamera->setView(Vec3(0, -340, 57), Vec3(0, 30, 20), Vec3(0, 0, 1)); presCamera->setQueueCullFunc([](int queue) { if (queue == 52) { return true; } return false; }); presCamera->setRenderTarget(renderTarget); presCamera->setClearColor(Color(169.0/255, 74.0/255, 174.0/255, 1)); SceneManager::instance().getRenderManager().addCamera(presCamera); SceneManager::instance().addRootNode(presCamera->getNode()); // create the normal geometry geometry = ShapeGenerater::instance().CreateBox(100, 10, 100, 20, 20, 20); boxNode = CreateMeshEntity(); SetMeshData(boxNode, geometry, renderTarget->getTexture()); rootNode->addChild(boxNode->getNode()); }
void StateManagerGL::syncState(const gl::State &state, const gl::State::DirtyBits &dirtyBits) { // TODO(jmadill): Investigate only syncing vertex state for active attributes for (auto dirtyBit : angle::IterateBitSet(dirtyBits | mLocalDirtyBits)) { switch (dirtyBit) { case gl::State::DIRTY_BIT_SCISSOR_TEST_ENABLED: setScissorTestEnabled(state.isScissorTestEnabled()); break; case gl::State::DIRTY_BIT_SCISSOR: setScissor(state.getScissor()); break; case gl::State::DIRTY_BIT_VIEWPORT: setViewport(state.getViewport()); break; case gl::State::DIRTY_BIT_DEPTH_RANGE: setDepthRange(state.getNearPlane(), state.getFarPlane()); break; case gl::State::DIRTY_BIT_BLEND_ENABLED: setBlendEnabled(state.isBlendEnabled()); break; case gl::State::DIRTY_BIT_BLEND_COLOR: setBlendColor(state.getBlendColor()); break; case gl::State::DIRTY_BIT_BLEND_FUNCS: { const auto &blendState = state.getBlendState(); setBlendFuncs(blendState.sourceBlendRGB, blendState.destBlendRGB, blendState.sourceBlendAlpha, blendState.destBlendAlpha); break; } case gl::State::DIRTY_BIT_BLEND_EQUATIONS: { const auto &blendState = state.getBlendState(); setBlendEquations(blendState.blendEquationRGB, blendState.blendEquationAlpha); break; } case gl::State::DIRTY_BIT_COLOR_MASK: { const auto &blendState = state.getBlendState(); setColorMask(blendState.colorMaskRed, blendState.colorMaskGreen, blendState.colorMaskBlue, blendState.colorMaskAlpha); break; } case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED: setSampleAlphaToCoverageEnabled(state.isSampleAlphaToCoverageEnabled()); break; case gl::State::DIRTY_BIT_SAMPLE_COVERAGE_ENABLED: setSampleCoverageEnabled(state.isSampleCoverageEnabled()); break; case gl::State::DIRTY_BIT_SAMPLE_COVERAGE: setSampleCoverage(state.getSampleCoverageValue(), state.getSampleCoverageInvert()); break; case gl::State::DIRTY_BIT_DEPTH_TEST_ENABLED: setDepthTestEnabled(state.isDepthTestEnabled()); break; case gl::State::DIRTY_BIT_DEPTH_FUNC: setDepthFunc(state.getDepthStencilState().depthFunc); break; case gl::State::DIRTY_BIT_DEPTH_MASK: setDepthMask(state.getDepthStencilState().depthMask); break; case gl::State::DIRTY_BIT_STENCIL_TEST_ENABLED: setStencilTestEnabled(state.isStencilTestEnabled()); break; case gl::State::DIRTY_BIT_STENCIL_FUNCS_FRONT: { const auto &depthStencilState = state.getDepthStencilState(); setStencilFrontFuncs(depthStencilState.stencilFunc, state.getStencilRef(), depthStencilState.stencilMask); break; } case gl::State::DIRTY_BIT_STENCIL_FUNCS_BACK: { const auto &depthStencilState = state.getDepthStencilState(); setStencilBackFuncs(depthStencilState.stencilBackFunc, state.getStencilBackRef(), depthStencilState.stencilBackMask); break; } case gl::State::DIRTY_BIT_STENCIL_OPS_FRONT: { const auto &depthStencilState = state.getDepthStencilState(); setStencilFrontOps(depthStencilState.stencilFail, depthStencilState.stencilPassDepthFail, depthStencilState.stencilPassDepthPass); break; } case gl::State::DIRTY_BIT_STENCIL_OPS_BACK: { const auto &depthStencilState = state.getDepthStencilState(); setStencilBackOps(depthStencilState.stencilBackFail, depthStencilState.stencilBackPassDepthFail, depthStencilState.stencilBackPassDepthPass); break; } case gl::State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT: setStencilFrontWritemask(state.getDepthStencilState().stencilWritemask); break; case gl::State::DIRTY_BIT_STENCIL_WRITEMASK_BACK: setStencilBackWritemask(state.getDepthStencilState().stencilBackWritemask); break; case gl::State::DIRTY_BIT_CULL_FACE_ENABLED: setCullFaceEnabled(state.isCullFaceEnabled()); break; case gl::State::DIRTY_BIT_CULL_FACE: setCullFace(state.getRasterizerState().cullMode); break; case gl::State::DIRTY_BIT_FRONT_FACE: setFrontFace(state.getRasterizerState().frontFace); break; case gl::State::DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED: setPolygonOffsetFillEnabled(state.isPolygonOffsetFillEnabled()); break; case gl::State::DIRTY_BIT_POLYGON_OFFSET: { const auto &rasterizerState = state.getRasterizerState(); setPolygonOffset(rasterizerState.polygonOffsetFactor, rasterizerState.polygonOffsetUnits); break; } case gl::State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED: setRasterizerDiscardEnabled(state.isRasterizerDiscardEnabled()); break; case gl::State::DIRTY_BIT_LINE_WIDTH: setLineWidth(state.getLineWidth()); break; case gl::State::DIRTY_BIT_PRIMITIVE_RESTART_ENABLED: setPrimitiveRestartEnabled(state.isPrimitiveRestartEnabled()); break; case gl::State::DIRTY_BIT_CLEAR_COLOR: setClearColor(state.getColorClearValue()); break; case gl::State::DIRTY_BIT_CLEAR_DEPTH: setClearDepth(state.getDepthClearValue()); break; case gl::State::DIRTY_BIT_CLEAR_STENCIL: setClearStencil(state.getStencilClearValue()); break; case gl::State::DIRTY_BIT_UNPACK_ALIGNMENT: // TODO(jmadill): split this setPixelUnpackState(state.getUnpackState()); break; case gl::State::DIRTY_BIT_UNPACK_ROW_LENGTH: // TODO(jmadill): split this setPixelUnpackState(state.getUnpackState()); break; case gl::State::DIRTY_BIT_UNPACK_IMAGE_HEIGHT: // TODO(jmadill): split this setPixelUnpackState(state.getUnpackState()); break; case gl::State::DIRTY_BIT_UNPACK_SKIP_IMAGES: // TODO(jmadill): split this setPixelUnpackState(state.getUnpackState()); break; case gl::State::DIRTY_BIT_UNPACK_SKIP_ROWS: // TODO(jmadill): split this setPixelUnpackState(state.getUnpackState()); break; case gl::State::DIRTY_BIT_UNPACK_SKIP_PIXELS: // TODO(jmadill): split this setPixelUnpackState(state.getUnpackState()); break; case gl::State::DIRTY_BIT_PACK_ALIGNMENT: // TODO(jmadill): split this setPixelPackState(state.getPackState()); break; case gl::State::DIRTY_BIT_PACK_REVERSE_ROW_ORDER: // TODO(jmadill): split this setPixelPackState(state.getPackState()); break; case gl::State::DIRTY_BIT_PACK_ROW_LENGTH: // TODO(jmadill): split this setPixelPackState(state.getPackState()); break; case gl::State::DIRTY_BIT_PACK_SKIP_ROWS: // TODO(jmadill): split this setPixelPackState(state.getPackState()); break; case gl::State::DIRTY_BIT_PACK_SKIP_PIXELS: // TODO(jmadill): split this setPixelPackState(state.getPackState()); break; case gl::State::DIRTY_BIT_DITHER_ENABLED: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_GENERATE_MIPMAP_HINT: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_SHADER_DERIVATIVE_HINT: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_READ_FRAMEBUFFER_OBJECT: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_DRAW_FRAMEBUFFER_OBJECT: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_RENDERBUFFER_BINDING: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_VERTEX_ARRAY_BINDING: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_VERTEX_ARRAY_OBJECT: state.getVertexArray()->syncImplState(); break; case gl::State::DIRTY_BIT_PROGRAM_BINDING: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_PROGRAM_OBJECT: // TODO(jmadill): implement this break; default: { ASSERT(dirtyBit >= gl::State::DIRTY_BIT_CURRENT_VALUE_0 && dirtyBit < gl::State::DIRTY_BIT_CURRENT_VALUE_MAX); size_t attribIndex = static_cast<size_t>(dirtyBit) - gl::State::DIRTY_BIT_CURRENT_VALUE_0; setAttributeCurrentData(attribIndex, state.getVertexAttribCurrentValue( static_cast<unsigned int>(attribIndex))); break; } } mLocalDirtyBits.reset(); } }
void State::initialize(const Caps& caps, GLuint clientVersion) { mMaxDrawBuffers = caps.maxDrawBuffers; mMaxCombinedTextureImageUnits = caps.maxCombinedTextureImageUnits; setClearColor(0.0f, 0.0f, 0.0f, 0.0f); mDepthClearValue = 1.0f; mStencilClearValue = 0; mRasterizer.rasterizerDiscard = false; mRasterizer.cullFace = false; mRasterizer.cullMode = GL_BACK; mRasterizer.frontFace = GL_CCW; mRasterizer.polygonOffsetFill = false; mRasterizer.polygonOffsetFactor = 0.0f; mRasterizer.polygonOffsetUnits = 0.0f; mRasterizer.pointDrawMode = false; mRasterizer.multiSample = false; mScissorTest = false; mScissor.x = 0; mScissor.y = 0; mScissor.width = 0; mScissor.height = 0; mBlend.blend = false; mBlend.sourceBlendRGB = GL_ONE; mBlend.sourceBlendAlpha = GL_ONE; mBlend.destBlendRGB = GL_ZERO; mBlend.destBlendAlpha = GL_ZERO; mBlend.blendEquationRGB = GL_FUNC_ADD; mBlend.blendEquationAlpha = GL_FUNC_ADD; mBlend.sampleAlphaToCoverage = false; mBlend.dither = true; mBlendColor.red = 0; mBlendColor.green = 0; mBlendColor.blue = 0; mBlendColor.alpha = 0; mDepthStencil.depthTest = false; mDepthStencil.depthFunc = GL_LESS; mDepthStencil.depthMask = true; mDepthStencil.stencilTest = false; mDepthStencil.stencilFunc = GL_ALWAYS; mDepthStencil.stencilMask = -1; mDepthStencil.stencilWritemask = -1; mDepthStencil.stencilBackFunc = GL_ALWAYS; mDepthStencil.stencilBackMask = -1; mDepthStencil.stencilBackWritemask = -1; mDepthStencil.stencilFail = GL_KEEP; mDepthStencil.stencilPassDepthFail = GL_KEEP; mDepthStencil.stencilPassDepthPass = GL_KEEP; mDepthStencil.stencilBackFail = GL_KEEP; mDepthStencil.stencilBackPassDepthFail = GL_KEEP; mDepthStencil.stencilBackPassDepthPass = GL_KEEP; mStencilRef = 0; mStencilBackRef = 0; mSampleCoverage = false; mSampleCoverageValue = 1.0f; mSampleCoverageInvert = false; mGenerateMipmapHint = GL_DONT_CARE; mFragmentShaderDerivativeHint = GL_DONT_CARE; mLineWidth = 1.0f; mViewport.x = 0; mViewport.y = 0; mViewport.width = 0; mViewport.height = 0; mNearZ = 0.0f; mFarZ = 1.0f; mBlend.colorMaskRed = true; mBlend.colorMaskGreen = true; mBlend.colorMaskBlue = true; mBlend.colorMaskAlpha = true; mActiveSampler = 0; const GLfloat defaultFloatValues[] = { 0.0f, 0.0f, 0.0f, 1.0f }; mVertexAttribCurrentValues.resize(caps.maxVertexAttributes); for (size_t attribIndex = 0; attribIndex < mVertexAttribCurrentValues.size(); ++attribIndex) { mVertexAttribCurrentValues[attribIndex].setFloatValues(defaultFloatValues); } mUniformBuffers.resize(caps.maxCombinedUniformBlocks); mTransformFeedbackBuffers.resize(caps.maxTransformFeedbackSeparateAttributes); mSamplerTextures[GL_TEXTURE_2D].resize(caps.maxCombinedTextureImageUnits); mSamplerTextures[GL_TEXTURE_CUBE_MAP].resize(caps.maxCombinedTextureImageUnits); if (clientVersion >= 3) { // TODO: These could also be enabled via extension mSamplerTextures[GL_TEXTURE_2D_ARRAY].resize(caps.maxCombinedTextureImageUnits); mSamplerTextures[GL_TEXTURE_3D].resize(caps.maxCombinedTextureImageUnits); } mSamplers.resize(caps.maxCombinedTextureImageUnits); mActiveQueries[GL_ANY_SAMPLES_PASSED].set(NULL); mActiveQueries[GL_ANY_SAMPLES_PASSED_CONSERVATIVE].set(NULL); mActiveQueries[GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN].set(NULL); mProgram = NULL; mReadFramebuffer = NULL; mDrawFramebuffer = NULL; }
c_Graphics::c_Graphics() { cam_x=cam_y=0; setClearColor(0.0f, 0.0f, 0.0f, 0.0f); setColor(1.0f, 1.0f, 1.0f, 0.0f); }
void ShadowsDemo::onDraw() { App::onDraw(); const auto device = graphicsDevice(); device->setClearColor(0.0f, 0.0f, 0.0f, 0.0f); device->clear(ciri::ClearFlags::Color | ciri::ClearFlags::Depth); device->setRasterizerState(_rasterState); device->restoreDefaultBlendState(); if( _spotlightShader->isValid() && _directionalShader->isValid() ) { const cc::Mat4f& cameraViewProj = _camera.getProj() * _camera.getView(); bool firstLight = true; Light::Type boundLightType = Light::Type::Invalid; for( auto& light : _lights ) { // compute light matrices //const cc::Mat4f& lightView = light.view(); //const cc::Mat4f& lightProj = light.proj();//cc::math::perspectiveRH(45.0f, 1.0f, 0.1f, light.range());//light.proj(); //const cc::Mat4f lightViewProj = lightProj * lightView; if( light.type() == Light::Type::Directional ) { //light.computeViewProjFromFrustum(BoundingFrustum(cameraViewProj)); light.computeViewProjFromFrustum(BoundingFrustum(_camera.getFov(), _camera.getAspect(), _camera.getNearPlane(), _camera.getFarPlane(), _camera.getPosition(), _camera.getFpsFront(), _camera.getUp())); //light.computeViewProjOrtho(_camera.getView(), _camera.getFov(), _camera.getAspect(), _camera.getNearPlane(), _camera.getFarPlane()); } const cc::Mat4f lightViewProj = light.proj() * light.view(); if( light.castShadows() ) { device->setDepthStencilState(device->getDefaultDepthStencilDefault()); // set and clear render target ciri::IRenderTarget2D* depthTarget = _shadowTarget.get(); device->setRenderTargets(&depthTarget, 1); device->setClearColor(0.0f, 0.0f, 0.0f, 0.0f); device->clear(ciri::ClearFlags::Color | ciri::ClearFlags::Depth); // apply depth shader device->applyShader(_depthShader); // set viewport to depth size device->setViewport(ciri::Viewport(0, 0, _shadowTarget->getDepth()->getWidth(), _shadowTarget->getDepth()->getHeight())); // render all models for( auto& mdl : _models ) { _depthConstants.xform = lightViewProj * mdl->getXform().getWorld(); _depthConstantsBuffer->setData(sizeof(DepthConstants), &_depthConstants); device->setVertexBuffer(mdl->getVertexBuffer()); if( mdl->getIndexBuffer() != nullptr ) { device->setIndexBuffer(mdl->getIndexBuffer()); device->drawIndexed(ciri::PrimitiveTopology::TriangleList, mdl->getIndexBuffer()->getIndexCount()); } else { device->drawArrays(ciri::PrimitiveTopology::TriangleList, mdl->getVertexBuffer()->getVertexCount(), 0); } } // reser viewport to screen device->setViewport(ciri::Viewport(0, 0, window()->getWidth(), window()->getHeight())); // restore default render targets device->restoreDefaultRenderTargets(); } switch( light.type() ) { case Light::Type::Directional: { if( boundLightType != Light::Type::Directional || light.castShadows() ) { boundLightType = Light::Type::Directional; device->applyShader(_directionalShader); device->setTexture2D(0, _shadowTarget->getDepth(), ciri::ShaderStage::Pixel); device->setSamplerState(0, _shadowSampler, ciri::ShaderStage::Pixel); } _directionalConstants.LightDirection = light.direction(); _directionalConstants.LightColor = light.diffuseColor(); _directionalConstants.LightIntensity = light.diffuseIntensity(); _directionalConstants.campos = _camera.getPosition(); _directionalConstants.CastShadows = light.castShadows(); _directionalConstants.lightViewProj = lightViewProj; for( auto& mdl : _models ) { if( !mdl->isValid() ) { continue; } _directionalConstants.world = mdl->getXform().getWorld(); _directionalConstants.xform = cameraViewProj * _directionalConstants.world; _directionalConstantsBuffer->setData(sizeof(DirectionalConstants), &_directionalConstants); device->setVertexBuffer(mdl->getVertexBuffer()); if( mdl->getIndexBuffer() != nullptr ) { device->setIndexBuffer(mdl->getIndexBuffer()); device->drawIndexed(ciri::PrimitiveTopology::TriangleList, mdl->getIndexBuffer()->getIndexCount()); } else { device->drawArrays(ciri::PrimitiveTopology::TriangleList, mdl->getVertexBuffer()->getVertexCount(), 0); } } break; } case Light::Type::Spot: { if( boundLightType != Light::Type::Spot || light.castShadows() ) { boundLightType = Light::Type::Spot; device->applyShader(_spotlightShader); device->setTexture2D(0, _shadowTarget->getDepth(), ciri::ShaderStage::Pixel); device->setSamplerState(0, _shadowSampler, ciri::ShaderStage::Pixel); } _spotlightConstants.LightPosition = light.position(); _spotlightConstants.LightDirection = light.direction(); _spotlightConstants.LightColor = light.diffuseColor(); _spotlightConstants.LightCosInner = light.cosConeInnerAngle(true); _spotlightConstants.LightCosOuter = light.cosConeOuterAngle(true); _spotlightConstants.LightIntensity = light.diffuseIntensity(); _spotlightConstants.LightRange = light.range(); _spotlightConstants.CastShadows = light.castShadows(); _spotlightConstants.lightViewProj = lightViewProj; for( auto& mdl : _models ) { _spotlightConstants.world = mdl->getXform().getWorld(); _spotlightConstants.xform = cameraViewProj * _spotlightConstants.world; _spotlightConstantsBuffer->setData(sizeof(SpotlightConstants), &_spotlightConstants); device->setVertexBuffer(mdl->getVertexBuffer()); if( mdl->getIndexBuffer() != nullptr ) { device->setIndexBuffer(mdl->getIndexBuffer()); device->drawIndexed(ciri::PrimitiveTopology::TriangleList, mdl->getIndexBuffer()->getIndexCount()); } else { device->drawArrays(ciri::PrimitiveTopology::TriangleList, mdl->getVertexBuffer()->getVertexCount(), 0); } } break; } } if( firstLight ) { firstLight = false; device->setBlendState(_additiveBlendState); } } } device->present(); }
void DisplayDevice::setClearColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { setClearColor(r/255.0f, g/255.0f, b/255.0f, a/255.0f); }
//behandelt exception interrupts void _isrException(unsigned int intNum) { setClearColor(CL_BLUE); clearScreen(); enum TEXT_COLOR color; color = getFgColor(); setFgColor(CL_WHITE); setCursor(40,10); switch(intNum) { case 0: { kprint("\nException: Division durch 0 ...\n"); }break; case 1: { kprint("\nException: Debuger ...\n"); }break; case 2: { kprint("\nException: Non Maskable Interrupt ...\n"); }break; case 3: { kprint("\nException: Breakpoint ...\n"); }break; case 4: { kprint("\nException: Into Detected Overflow ...\n"); }break; case 5: { kprint("\nException: Out of Bounds ...\n"); }break; case 6: { kprint("\nException: Invalid Opcode ...\n"); }break; case 7: { kprint("\nException: No Coprocessor ...\n"); }break; case 8: { kprint("\nException: Double Fault ...\n"); }break; case 9: { kprint("\nException: Coprocessor Segment Overrun ...\n"); }break; case 10: { kprint("\nException: Bad TSS ...\n"); }break; case 11: { kprint("\nException: Segment Not Present ...\n"); }break; case 12: { kprint("\nException: Stack Fault ...\n"); }break; case 13: { kprint("\nException: General Protection Fault ...\n"); }break; case 14: { kprint("\nException: Page Fault ...\n"); }break; case 15: { kprint("\nException: Unknown Interrupt ...\n"); }break; case 16: { kprint("\nException: Coprocessor Fault ...\n"); }break; case 17: { kprint("\nException: Alignment Check ...\n"); }break; case 18: { kprint("\nException: Machine Check ...\n"); }break; default: { kprint("\nException: Von Intel reserviert ...\n"); }break; }; kprint("System angehalten. Bitte neustarten!\n"); setFgColor(color); for (;;); }
void ClearFrameBuffer::setOptionalsToDefaults() { SingleAttribute::setOptionalsToDefaults(); setClearColor( vgm::Vec4f(0.f, 0.f, 0.f, 0.f) ); }