Beispiel #1
0
	bool initialize()
	{
		Message("Initialize started...", gines::Message::Info);

		SDL_Init(SDL_INIT_VIDEO);
		mWindow = SDL_CreateWindow("SDL project",
			SDL_WINDOWPOS_UNDEFINED,
			SDL_WINDOWPOS_UNDEFINED,
			WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL);

		if (mWindow == NULL)
		{
			Message("Initialization failed! Failed to create window!", gines::Message::Fatal);
			return false;
		}

		if ((renderingContex = SDL_GL_CreateContext(mWindow)) == NULL)
		{
			Message("Initialization failed! Failed to create SDL rendering context!", gines::Message::Fatal);
			return false;
		}

		if (glewInit() != GLEW_OK)
		{
			Message("Initialization failed! Failed to initializez glew!", gines::Message::Fatal);
			return false;
		}

		if (!gines::initializeTime())
		{
			Message("Initialization failed! Failed to initialize time!", gines::Message::Fatal);
			return false;
		}

		if (console.initialize() != 0)
		{
			Message("Initialization failed! Failed to initialize console!", gines::Message::Fatal);
			return false;
		}

		//GUI camera instance initialization
		guiCamera.setViewport(glm::vec2(0, 0), glm::vec2(WINDOW_WIDTH, WINDOW_HEIGHT));
		guiCamera.setPosition(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2);
		for (unsigned i = 0; i < cameras.size(); i++)
		{//Remove from cameras vector
			if (cameras[i] == &guiCamera)
			{
				cameras.erase(cameras.begin() + i);
				break;
			}
		}
		
		initializeShaders(); 

		glClearColor(0.003f, 0.01f, 0.003f, 10.0f); //0.003f, 0.01f, 0.003f, 1.0f
		Message("Initialized successfully!", gines::Message::Info);
		Message("Powered by... Gines(2015)", gines::Message::Info);
		return true;

	}
void GameOfLifeWorldRenderer::initialize()
{
	initializeShaders();

	instanceVertexBufferObject = VertexBufferObject::generate();

	GLfloat quadVertices[] = {
		-0.005f,  0.005f,
		0.005f, -0.005f,
		-0.005f, -0.005f,

		-0.005f,  0.005f,
		0.005f, -0.005f,
		0.005f,  0.005f,
	};

	quadVertexArrayObject = VertexArrayObject::generate();
	quadVertexBufferObject = VertexBufferObject::generate();

	quadVertexArrayObject.bind();
	quadVertexBufferObject.setData(quadVertices, GL_STATIC_DRAW);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (GLvoid*)0);

	instanceVertexBufferObject.bind();
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Quad), (GLvoid*)offsetof(Quad, position));
	glVertexAttribDivisor(1, 1);
	glEnableVertexAttribArray(2);
	glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Quad), (GLvoid*)offsetof(Quad, color));
	glVertexAttribDivisor(2, 1);
	instanceVertexBufferObject.unbind();

	quadVertexArrayObject.unbind();
}
int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
	glutInitWindowPosition(100,100);
	glutInitWindowSize(RENDER_WIDTH,RENDER_HEIGHT);
	glutCreateWindow("GLSL Shadow mapping");
	
	// This call will grab openGL extension function pointers.
	// This is not necessary for macosx and linux
	generateShadowFBO();
	loadShadowShader();
	
	
	// This is important, if not here, FBO's depthbuffer won't be populated.
	glEnable(GL_DEPTH_TEST);
	glClearColor(0,0,0,1.0f);
	
	glEnable(GL_CULL_FACE);
	
	glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);	
	
	glutDisplayFunc(renderScene);
	glutIdleFunc(renderScene);
	glutKeyboardFunc(keyboard);
	glutSpecialFunc(keySpecial);
	glutPassiveMotionFunc(mouseMoved);
	//glutKeyboardFunc(processNormalKeys);
	
	shaderProgram = initializeShaders("perPixel.vert", "perPixel.frag");
	toonProgram = initializeShaders("toon.vert", "toon.frag");
	//loadTextures();
	static GLfloat angle = 0.0;
	for(int x=0; x<45; x++)
	{
		
		for(int y=0; y<45; y++)
		{
			angle = x * 2.0 * 3.14159265 / 45;
			points[x][y][0]=float((x/5.0f)-4.5f);
			points[x][y][1]=float((y/5.0f)-4.5f);
			points[x][y][2]=float(sin((((x/5.0f)*40.0f)/360.0f)*3.141592654*2.0f));
		}
	}

	glutMainLoop();
}
Beispiel #4
0
void cwGLGridPlane::initialize()
{
    initializeShaders();
    initializeGeometry();

    vVertex = Program->attributeLocation("vVertex");

}
void ShapeRenderer2D::reloadShaders()
{
    if (_renderEngine != nullptr)
    {
        _renderEngine->disconnectProgram();
        delete _renderEngine;
        _renderEngine = new us::UniShader();
    }
    initializeShaders();
}
Beispiel #6
0
void KisOpenGLCanvas2::initializeGL()
{
    KisOpenGL::initializeContext(context());
    initializeOpenGLFunctions();

    KisConfig cfg;
    d->openGLImageTextures->setProofingConfig(canvas()->proofingConfiguration());
    d->openGLImageTextures->initGL(context()->functions());
    d->openGLImageTextures->generateCheckerTexture(createCheckersImage(cfg.checkSize()));

    initializeShaders();

    // If we support OpenGL 3.2, then prepare our VAOs and VBOs for drawing
    if (KisOpenGL::hasOpenGL3()) {
        d->quadVAO.create();
        d->quadVAO.bind();

        glEnableVertexAttribArray(PROGRAM_VERTEX_ATTRIBUTE);
        glEnableVertexAttribArray(PROGRAM_TEXCOORD_ATTRIBUTE);

        // Create the vertex buffer object, it has 6 vertices with 3 components
        d->quadBuffers[0].create();
        d->quadBuffers[0].setUsagePattern(QOpenGLBuffer::StaticDraw);
        d->quadBuffers[0].bind();
        d->quadBuffers[0].allocate(d->vertices, 6 * 3 * sizeof(float));
        glVertexAttribPointer(PROGRAM_VERTEX_ATTRIBUTE, 3, GL_FLOAT, GL_FALSE, 0, 0);

        // Create the texture buffer object, it has 6 texture coordinates with 2 components
        d->quadBuffers[1].create();
        d->quadBuffers[1].setUsagePattern(QOpenGLBuffer::StaticDraw);
        d->quadBuffers[1].bind();
        d->quadBuffers[1].allocate(d->texCoords, 6 * 2 * sizeof(float));
        glVertexAttribPointer(PROGRAM_TEXCOORD_ATTRIBUTE, 2, GL_FLOAT, GL_FALSE, 0, 0);

        // Create the outline buffer, this buffer will store the outlines of
        // tools and will frequently change data
        d->outlineVAO.create();
        d->outlineVAO.bind();

        glEnableVertexAttribArray(PROGRAM_VERTEX_ATTRIBUTE);

        // The outline buffer has a StreamDraw usage pattern, because it changes constantly
        d->lineBuffer.create();
        d->lineBuffer.setUsagePattern(QOpenGLBuffer::StreamDraw);
        d->lineBuffer.bind();
        glVertexAttribPointer(PROGRAM_VERTEX_ATTRIBUTE, 3, GL_FLOAT, GL_FALSE, 0, 0);
    }

    ptr_glLogicOp = (kis_glLogicOp)(context()->getProcAddress("glLogicOp"));

    Sync::init(context());

    d->canvasInitialized = true;
}
Beispiel #7
0
	virtual bool initialize() {
		if (!initializeShaders()) {
			return false;
		}
		if (!initializeEnvironment()) {
			return false;
		}
		
		camera.position = matrix3x1(0, 40, 0);
		
		return true;
	}
Beispiel #8
0
void TriangleWindow::initialize()
{
    initializeLighting();
    glClearColor(0.0f,0.21f,0.21f,1.0f);
    glColor3f(1.0f,1.0f,1.0f);
   glEnable(GL_DEPTH_TEST);    //Z-Buffer
   glDepthFunc(GL_LEQUAL); // Lesser or Equals
   glEnable(GL_CULL_FACE);
   glShadeModel(GL_SMOOTH);
   initializeShaders();
   initializeTextures();
   initializeVBO();

//   glEnable(GL_TEXTURE_2D);
}
    //!
    virtual bool initialize() {
        float zero = 0.0f;

        const int N = 128;

        camera = render::Camera(math::matrix3x1<float>(0, 0, 10.0f));

        oceanTexture = new render::Texture("media/textures/surfaces/ocean-ripples.jpg");
        oceanHeightMap = new simulation::OceanHeightMap(N, N, matrix3x1(20, 0, 0));
        heightMapTile = new HeightMapTile(N - 1, N - 1);

        heightsAndNormals = new math::matrix3x1<float>[N * N];

        if (!initializeShaders()) {
            return false;
        }

        return true;
    }
Beispiel #10
0
// Inicjalizuje meshe i parametry opengl
void init() {
	initializeShaders();

	try {
		g_pCylinderMesh = new Framework::Mesh("UnitCylinder.xml");
		g_pShpere1Mesh = new Framework::Mesh("Sphere1.xml");
		g_pShpere2Mesh = new Framework::Mesh("Sphere2.xml");
		g_pPlaneMesh = new Framework::Mesh("LargePlane.xml");
		g_pCubeMesh = new Framework::Mesh("UnitCube.xml");
		g_pTetrahedron1Mesh = new Framework::Mesh("UnitTetrahedron1.xml");
	} catch(std::exception &except) {
		printf("%s\n", except.what());
		throw;
	}

 	glutMouseFunc(MouseButton);
 	glutMotionFunc(MouseMotion);
	glutMouseWheelFunc(MouseWheel);
	glutKeyboardUpFunc(onKeyUp);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CW);

	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glDepthFunc(GL_LEQUAL);
	glDepthRange(0.0f, 1.0f);
	glEnable(GL_DEPTH_CLAMP);

	glGenBuffers(1, &g_projectionUniformBuffer);
	glBindBuffer(GL_UNIFORM_BUFFER, g_projectionUniformBuffer);
	glBufferData(GL_UNIFORM_BUFFER, sizeof(ProjectionBlock), NULL, GL_DYNAMIC_DRAW);

	glBindBufferRange(GL_UNIFORM_BUFFER, projectionBlockIndex, g_projectionUniformBuffer,
		0, sizeof(ProjectionBlock));

	glBindBuffer(GL_UNIFORM_BUFFER, 0);
}
void ShapeRenderer2D::init()
{
    _renderEngine = new us::UniShader();
    initializeShaders();
}
Beispiel #12
0
Window::Window(bool fullscreen, unsigned int width, unsigned int height)
    : vertexBuffer(0),
    indexBuffer(0),
    program(0),
    vertexShader(0),
    fragmentShader(0),
    texture(0)
{
    glfwSetErrorCallback(glfwErrorCallback);
    if (!glfwInit())
    {
        throw std::runtime_error(
                  "Could not open window: GLFW failed to initialize");
    }

#if defined(DEBUG)
    #if defined(GLFW_OPENGL_DEBUG_CONTEXT)
    glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
    #else
    LogInfo("OpenGL debug context not available");
    #endif // if defined(GLFW_OPENGL_DEBUG_CONTEXT)
#endif // if defined(DEBUG)

    // glfwSwapInterval(1); // VSYNC
    auto fullscreen_monitor = fullscreen ? glfwGetPrimaryMonitor() : NULL;
    glfwWindow = glfwCreateWindow(width,
                                  height,
                                  "mdetect",
                                  fullscreen_monitor,
                                  NULL);
    if (glfwWindow == NULL)
    {
        glfwTerminate();
        throw std::runtime_error(
                  "Could not open window: GLFW could not open window");
    }

    glfwMakeContextCurrent(glfwWindow);
    ///////////// GLEW INIT
    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        throw std::runtime_error(
                  "Could not open window: GLEW failed to initialize");
    }
    if (!GLEW_VERSION_3_3)
    {
        throw std::runtime_error(
                  "Your graphics card/driver does not support OpenGL 3.3");
    }
#if defined(DEBUG) && defined(GLFW_OPENGL_DEBUG_CONTEXT)
    LogDebug("Enabling OpenGL debug output");
    if (glewIsSupported("GL_ARB_debug_output"))
    {
        glDebugMessageCallbackARB(oglErrorCallback, NULL);
    }
    else
    {
        LogWarning("No support for OpenGL debug output found!");
    }
#endif // if defined(DEBUG) && defined(GLFW_OPENGL_DEBUG_CONTEXT)

    glfwSetWindowSizeCallback(glfwWindow, resizeCallback);

    glViewport(0, 0, width, height);

    GLfloat vertices[8] =
    {
        -1.0f, -1.0f,
        1.0f,  -1.0f,
        -1.0f, 1.0f,
        1.0f,  1.0f
    };

    GLuint indices[6] =
    {
        0, 1, 2,
        2, 1, 3
    };

    GLfloat textureCoordinates[8] =
    {
        0.0f, 1.0f,
        1.0f, 1.0f,
        0.0f, 0.0f,
        1.0f, 0.0f,
    };

    glGenBuffers(1, &vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER,
                 8 * sizeof(GLfloat),
                 &vertices[0],
                 GL_STATIC_DRAW);

    glGenBuffers(1, &indexBuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER,
                 6 * sizeof(GLuint),
                 &indices[0],
                 GL_STATIC_DRAW);

    glGenBuffers(1, &uvBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, uvBuffer);
    glBufferData(GL_ARRAY_BUFFER,
                 8 * sizeof(GLfloat),
                 &textureCoordinates[0],
                 GL_STATIC_DRAW);

    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*) 0);

    glEnableVertexAttribArray(1);
    glBindBuffer(GL_ARRAY_BUFFER, uvBuffer);
    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*) 0);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);

    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    initializeShaders();
}
Beispiel #13
0
//===========================================================================
void cGenericShader::onDisplayReset(const bool a_affectChildren)
{
    uninitializeShaders();
    initializeShaders();
    cGenericObject::onDisplayReset(a_affectChildren);
}
Beispiel #14
0
void cwGLScraps::initialize() {
    initializeShaders();
}
Beispiel #15
0
 SharedGLData(GLContext glContext) : stencilIndex(1)
 {
     glContextDataMap().add(glContext, this);
     initializeShaders();
 }