示例#1
0
bool Engine::init() {
	if (!app) {
		Log::print("App not informed");
		return false;
	}

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

	setupOpenGL();

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

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

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

	printVersions();

	if (!app->init()) {
		return false;
	}

	reshape();

	return true;
}
示例#2
0
int Game::init()
{
  mInMenu = true;
  mMenuOption = 0;
  mQuitDone = false;
  mLevel = 0;
  int error = initSDL();
  if(error == 0) error = initGLEW();
  if(error == 0) error = initGL();

  if (!mMusic.load("./music/Sardonica_-_Through_to_Reality__Original_.mp3")) {
    error = 30;
  }
  mMusic.play(true);

  if (!mHud.init()) {
    error = 40;
  }

  if (!mMenu.init()){
    error = 50;
  }

  mWinSound.load("./sounds/you_win.wav");
  mLoseSound.load("./sounds/you_lose.wav");

  return error;
}
示例#3
0
bool Window::configInit()
{
    GLXFBConfig* fbConfig = chooseGLXFBConfig();
    if( !fbConfig )
    {
        sendError( ERROR_SYSTEMWINDOW_PIXELFORMAT_NOTFOUND );
        return false;
    }

    GLXContext context = createGLXContext( fbConfig );
    setGLXContext( context );
    if( !context )
    {
        XFree( fbConfig );
        return false;
    }

    bool success = configInitGLXDrawable( fbConfig );
    XFree( fbConfig );

    if( !success || !_impl->xDrawable )
    {
        sendError( ERROR_GLXWINDOW_NO_DRAWABLE );
        return false;
    }

    makeCurrent();
    initGLEW();
    _initSwapSync();
    if( getIAttribute( IATTR_HINT_DRAWABLE ) == FBO )
        success = configInitFBO();

    return success;
}
		RenderWindow::RenderWindow(const WindowParams& params)
		{
			// TODO: options

			// FSAA
			//::glfwWindowHint(GLFW_SAMPLES, 16);

			::glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 3);
			::glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 3);

			//::glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
			//::glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);

			::glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
			::glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

			// TODO: monitor & res selection
			GLFWmonitor* mon = ::glfwGetPrimaryMonitor();
			const GLFWvidmode* mode = ::glfwGetVideoMode(mon);

			m_window = std::shared_ptr<GLFWwindow>(::glfwCreateWindow(params.width, params.height, params.title.c_str(), NULL, NULL), ::glfwDestroyWindow);
			if (m_window == nullptr)
				throw Commons::UnknownException("Can't create GLFW window");
			::glfwMakeContextCurrent(m_window.get());
			::glfwSetWindowUserPointer(m_window.get(), this);

			//::glfwSetInputMode(m_window.get(), GLFW_CURSOR, GLFW_CURSOR_DISABLED);
			//::glfwSetCursorPosCallback(m_window.get(), CursorCallbackStatic); // TODO: not needed? (have events)

			initGLEW();
		}
示例#5
0
int main(int argc, char** argv) {

	for (int i = 0; i < M.GetLayers(); i++)
	{
		M.Show(i);
		printf("\n");
	}

	current_elevator_i = M.getElevatorI();
	current_elevator_j = M.getElevatorJ();

	fvc = read_obj("flashlight.obj", fv, ftv, fn);

	initGLUT(&argc, argv);
	initGLEW();
	initOpenGL();

	
	glutKeyboardFunc(Movement);
	glutWarpPointer(200, 200);
	glutMotionFunc(MouseActiveMotion);
	glutPassiveMotionFunc(MouseMotion);
	glutMouseFunc(MouseButtons);
	glutMainLoop();

	freeVAO();
	freeVBO();
	cleanShaders();
	return 0;
}
示例#6
0
文件: App.cpp 项目: Nitrooos/Kastle
void App::onInit() {
    initSFML();
    initGLEW();

    grMananger.reset(new GraphicsManager());
    loadingScreen.reset(new LoadingScreen(window, grMananger.get()));
    world.reset(new World(grMananger.get()));
}
示例#7
0
文件: main.cpp 项目: recreate/Bound
int main(int argc, char* argv[]) {
	struct config* cfg = getConfiguration();
	initSDL(cfg);
	
	initGLEW();
	
	init();
	mainLoop();
	
	cleanup();
	return 0;
}
示例#8
0
int main(int argc, char** argv){
	globalEngine = new Engine();
	globalCamera = new Camera();
	
	initGLUT(&argc, argv);
	initGLEW();
	loadModels();
	
	initOpenGL();
	glutMainLoop();
	return 0;
}
示例#9
0
void OpenGLHelper::initOpenGL(int *argc, char** argv, string windowCaption, int windowXPosition, int windowYPosition, int windowWidth, int windowHeight)
{
	initGLUT(argc, argv, windowCaption, windowXPosition, windowYPosition, windowWidth, windowHeight);
	initGLEW();	

	glEnable(GL_LIGHTING);
	glEnable(GL_COLOR_MATERIAL);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHT0);
	glEnable(GL_NORMALIZE);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);
	GLint textureUnits = 3;
	glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &textureUnits);
示例#10
0
bool Renderer::init(::Display* display, ::Window window, GLXFBConfig& fbc)
{
    sbAssert(display, "display is null");

    mDisplay = display;

    gLog.info("creating GL context...\n");
    int contextAttribs[] = {
        GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
        GLX_CONTEXT_MINOR_VERSION_ARB, 3,
        GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
        0
    };

    GLXCREATECTXATTRSARBPROC glXCreateContextAttribsARB = (GLXCREATECTXATTRSARBPROC)glXGetProcAddress((GLubyte*)"glXCreateContextAttribsARB");
    if (!glXCreateContextAttribsARB) {
        gLog.err("glXCreateContextAttribsARB not present\n");
        return false;
    }

    GL_CHECK(mGLContext = glXCreateContextAttribsARB(mDisplay, fbc, 0, True, contextAttribs));
    if (!mGLContext) {
        gLog.err("glXCreateContextAttribsARB failed\n");
        return false;
    }

    GL_CHECK(glXMakeCurrent(mDisplay, window, mGLContext));
    printGLVersion();

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

    GL_CHECK(glEnable(GL_DEPTH_TEST));
    GL_CHECK(glDepthFunc(GL_LESS));

    GL_CHECK(glEnable(GL_CULL_FACE));
    GL_CHECK(glCullFace(GL_BACK));

    GL_CHECK(glEnable(GL_BLEND));
    GL_CHECK(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));

#if 0
    GL_CHECK(glEnable(GL_TEXTURE_2D));

    String::init(mDisplay);
#endif

    return true;
}
示例#11
0
bool Window::configInit()
{
    AGLPixelFormat pixelFormat = chooseAGLPixelFormat();
    if( !pixelFormat )
        return false;

    AGLContext context = createAGLContext( pixelFormat );
    destroyAGLPixelFormat ( pixelFormat );
    setAGLContext( context );

    if( !context )
        return false;

    makeCurrent();
    initGLEW();
    return configInitAGLDrawable();
}
示例#12
0
文件: Engine.cpp 项目: akkenoth/eel
void Engine::initGLUT() {
	int argc = 1;
	char *argv[] = {"Bin", NULL};
	glutInit(&argc, argv);

	if(context->core) {
		glutInitContextVersion(context->majorVersion, context->minorVersion);
		glutInitContextProfile(GLUT_CORE_PROFILE);
	} else {
		glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE);
	}

	glutInitDisplayMode(framebuffer->flags);
	glutInitWindowPosition(window->positionX, window->positionY);
	glutInitWindowSize(window->width, window->height);
	// in case GL_DEBUG_OUTPUT doesn't work
	// glutInitContextFlags(GLUT_DEBUG);
	glutCreateWindow(window->name.c_str());

	std::cout << "GLUT initialized\n";
	glEnable(GL_DEBUG_OUTPUT);

	glutSetWindowData(static_cast<void *>(this));

	glutIdleFunc(idleCallback);
	glutDisplayFunc(displayCallback);
	glutReshapeFunc(reshapeCallback);
	glutCloseFunc(closeCallback);

	glutKeyboardFunc(handleKeyboardCallback);
	glutKeyboardUpFunc(handleKeyboardUpCallback);
	glutSpecialFunc(handleKeyboardSpecialCallback);
	glutSpecialUpFunc(handleKeyboardSpecialUpCallback);
	glutMotionFunc(handleMouseMovement);
	glutPassiveMotionFunc(handleMouseMovement);

	initGLEW();

	glDebugMessageCallback(DebugOutput::printDebugOutput, NULL);
	//GLenum severity = GL_DEBUG_SEVERITY_LOW | GL_DEBUG_SEVERITY_MEDIUM | GL_DEBUG_SEVERITY_HIGH | GL_DEBUG_SEVERITY_NOTIFICATION;
	glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
	glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_NOTIFICATION, 0, NULL, GL_FALSE);
	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);

	std::cout << "Info | Vendor: " << glGetString(GL_VENDOR) << " | Renderer: " << glGetString(GL_RENDERER) << " | OpenGl version: " << glGetString(GL_VERSION) << std::endl;
}
示例#13
0
    bool Root::init(bool fullscr, int w, int h)
    {
        LOG_INFO("loading root");

        windowWidth = w;
        windowHeight = h;
        fullscreen = fullscr;

        if(!initGLFW()) return false;
        if(!initGLEW()) return false;

        // set GL stuff
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_CULL_FACE);

        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

        //Call these in the right order: Models need Textures
        TextureManager::shared().initialize();
		//MaterialManager::shared().initialize();
        ModelManager::shared().initialize();

        overlay = new Overlay();
        if(!overlay->init()) return false;

        Interface* interf = new Interface;
        if(!interf->init())
        {
          LOG_INFO("Could not initialize interface");
          return false;
        }
        addFrameListener(interf);

        Console* console = new Console;
        if(!console->init()) 
        {
          LOG_INFO("Could not initialize console");
          return false;
        }
        addFrameListener(console);
        addInputListener(console);
        LOG_INFO("Root initialized");

        return true;
    }
示例#14
0
// Main entry point.
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    globals.width = 1000;
    globals.height = 700;
    glutInitWindowSize(globals.width, globals.height);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Particel");
    initGLEW();
    displayOpenGLInfo();
    init();
    glutReshapeFunc(&reshape);
    glutDisplayFunc(&display);
    glutIdleFunc(&idle);
    glutMainLoop();

    return EXIT_SUCCESS;
}
示例#15
0
文件: main.cpp 项目: gakimaru2/public
int main(const int argc, const char* argv[])
{
	printf("<< %s >>\n", TITLE);

	//GLU initialize
	{
		initGLUT(argc, argv);
		createGLUTWindow();
	}

	//GLEW initialize
	{
		const GLenum result = initGLEW();
		if (result != GLEW_OK){ abort_program(); return EXIT_FAILURE; }
	}
	{
		printGLEWInfo();
		const bool result = checkGLEWFunctions();
		if (!result){ abort_program(); return EXIT_FAILURE; }
	}

	//Shader initialize
	const GLuint vertex_shader_handle = createAndLoadVertexShaderAll();
	if (!vertex_shader_handle){ abort_program(); return EXIT_FAILURE; }
	const GLuint fragment_shader_handle = createAndLoadFragmentShaderAll();
	if (!fragment_shader_handle){ abort_program(); return EXIT_FAILURE; }
	const GLuint program_handle = createAndLinkShaderProgram(vertex_shader_handle, fragment_shader_handle);
	g_program_handle = program_handle;

	printActiveAttribInfo(program_handle);
	printActiveUniformInfo(program_handle);
	
	//GLM test
	testGLM();

	//Main loop
	setupGLUTFunctions();
	mainloopGLUT();

	return EXIT_SUCCESS;
}
示例#16
0
文件: Window.cpp 项目: fr0zi/vbcpp
bool Window::createWindow(int w = 1024, int h = 768, int posx = 100, int posy = 100)
{
    _width = w;
    _height = h;
    _xPos = posx;
    _yPos = posy;

    if ( !glfwInit() )
    {
        fprintf( stderr, "VIDEO: Failed to initialize GLFW!\n");
        //exit(EXIT_FAILURE);
        return false;
    }

    // Set OpenGL characteristics
    glfwWindowHint(GLFW_SAMPLES, 4); //4x antialiasing
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	glfwWindowHint( GLFW_RESIZABLE, GL_FALSE );

	// Create window with given size and title
	_win = glfwCreateWindow(_width, _height, _title.c_str(), NULL, NULL);

	if (!_win)
        return false;

    // Make window active, set position on the screen and title
	glfwMakeContextCurrent(_win);
	glfwSetWindowPos(_win, _xPos, _yPos);

    if (!initGLEW())
        return false;


    return true;
}
示例#17
0
int main(int argc, char** argv)
{
 al= sl= dl= gam= inv= zoom=1.0;
	inv=0;
    glutInit(&argc, argv);
    globals.width = 800;
    globals.height = 600;
    glutInitWindowSize(globals.width, globals.height);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Model viewer");
    initGLEW();
    displayOpenGLVersion();
    init();
    glutReshapeFunc(&reshape);
    glutDisplayFunc(&display);
    glutKeyboardFunc(&keyboard);
    glutMouseFunc(&mouse);
    glutMotionFunc(&motion);
    glutIdleFunc(&idle);
    glutMainLoop();

    return EXIT_SUCCESS;
}
示例#18
0
int main(int argc, char* argv[]) {
  // initialization and window creation
  initGLFW();
  GLFWwindow* window = createWindow(800, 600, "Learn OpenGL");
  glfwSetKeyCallback(window, glfwKeyCallback);
  if (window == nullptr) return -1;
  glfwMakeContextCurrent(window);
  if (initGLEW() != GLEW_OK) return -1;
  
  glViewport(0, 0, 800, 600);
  
  // game loop
  while (!glfwWindowShouldClose(window)) {
    glfwPollEvents();

    glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    glfwSwapBuffers(window);
  }
  
  glfwTerminate();
  return 0;
}
示例#19
0
int main()
{
	GLFWwindow* window;
	const int WIDTH = 800, HEIGHT = 600;
	char* WINDOW_NAME = "OpenGL - basic stuff";
	initContext();
	window = glfwCreateWindow(WIDTH, HEIGHT, WINDOW_NAME, nullptr, nullptr);
	glfwMakeContextCurrent(window);

	glfwSetKeyCallback(window, key_callback);
	glfwSetCursorPosCallback(window, mouse_callback);
	glfwSetScrollCallback(window, scroll_callback);
	//glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

	initGLEW();

	// Create VAOs
	GLuint vaoCube, vaoQuad, vaoLight;
	glGenVertexArrays(1, &vaoCube);
	glGenVertexArrays(1, &vaoQuad);
	glGenVertexArrays(1, &vaoLight);

	// Load vertex data
	GLuint vboCube, vboQuad;
	glGenBuffers(1, &vboCube);
	glGenBuffers(1, &vboQuad);

	glBindBuffer(GL_ARRAY_BUFFER, vboCube);
	glBufferData(GL_ARRAY_BUFFER, sizeof(cubeVertices), cubeVertices, GL_STATIC_DRAW);

	glBindBuffer(GL_ARRAY_BUFFER, vboQuad);
	glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), quadVertices, GL_STATIC_DRAW);

	// Create shader programs
	GLuint sceneVertexShader, sceneFragmentShader, sceneShaderProgram;
	createShaderProgram(readShaderFile("basic.vert"), readShaderFile("basic.frag"), sceneVertexShader, sceneFragmentShader, sceneShaderProgram);

	GLuint screenVertexShader, screenFragmentShader, screenShaderProgram;
	createShaderProgram(readShaderFile("basic_screen.vert"), readShaderFile("basic_screen.frag"), screenVertexShader, screenFragmentShader, screenShaderProgram);

	// Specify the layout of the vertex data
	glBindVertexArray(vaoCube);
	glBindBuffer(GL_ARRAY_BUFFER, vboCube);
	specifySceneVertexAttributes(sceneShaderProgram);

	glBindVertexArray(vaoQuad);
	glBindBuffer(GL_ARRAY_BUFFER, vboQuad);
	specifyScreenVertexAttributes(screenShaderProgram);

	glBindVertexArray(vaoLight);
	glBindBuffer(GL_ARRAY_BUFFER, vboCube);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid*)0); // Note that we skip over the other data in our buffer object (we don't need the normals/textures, only positions).
	glEnableVertexAttribArray(0);
	glBindVertexArray(0);

	// Load textures
	GLuint diffuseMap = loadTextureMap("container2.png");
	GLuint specularMap = loadTextureMap("container2_specular.png");

	glUseProgram(sceneShaderProgram);
	glUniform1i(glGetUniformLocation(sceneShaderProgram, "texKitten"), 0);
	glUniform1i(glGetUniformLocation(sceneShaderProgram, "texPuppy"), 1);

	glUseProgram(screenShaderProgram);
	glUniform1i(glGetUniformLocation(screenShaderProgram, "texFramebuffer"), 0);

	GLint uniModel = glGetUniformLocation(sceneShaderProgram, "model");

	// Create frame buffer
	GLuint frameBuffer;
	glGenFramebuffers(1, &frameBuffer);
	glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);

	// Create texture to hold color buffer
	GLuint texColorBuffer;
	glGenTextures(1, &texColorBuffer);
	glBindTexture(GL_TEXTURE_2D, texColorBuffer);

	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 800, 600, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texColorBuffer, 0);

	// Create Renderbuffer Object to hold depth and stencil buffers
	GLuint rboDepthStencil;
	glGenRenderbuffers(1, &rboDepthStencil);
	glBindRenderbuffer(GL_RENDERBUFFER, rboDepthStencil);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 800, 600);
	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rboDepthStencil);	

	glm::mat4 viewMatrix = glm::lookAt(
		glm::vec3(2.5f, 2.5f, 2.0f),
		glm::vec3(0.0f, 0.0f, 0.0f),
		glm::vec3(0.0f, 0.0f, 1.0f));
	GLint uniView = glGetUniformLocation(sceneShaderProgram, "view");
	glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(viewMatrix));

	glm::mat4 projMatrix = glm::perspective(camera.Zoom, (float)WIDTH / (float)HEIGHT, 0.1f, 100.0f);
	GLint uniProj = glGetUniformLocation(sceneShaderProgram, "proj");
	glUniformMatrix4fv(uniProj, 1, GL_FALSE, glm::value_ptr(projMatrix));

	GLint uniColor = glGetUniformLocation(sceneShaderProgram, "overrideColor");

	GLint timer = glGetUniformLocation(sceneShaderProgram, "timer");

	while (!glfwWindowShouldClose(window))
	{
		GLfloat currentFrame = glfwGetTime();
		deltaTime = currentFrame - lastFrame;
		lastFrame = currentFrame;

		glfwPollEvents();
		Do_Movement();

		// Bind our framebuffer and draw 3D scene(spinning cube)
		glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
		glBindVertexArray(vaoCube);
		glEnable(GL_DEPTH_TEST);
		glUseProgram(sceneShaderProgram);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, texKitten);
		glActiveTexture(GL_TEXTURE1);
		glBindTexture(GL_TEXTURE_2D, texPuppy);

		// Clear the screen to white
		glClearColor(.2f, .2f, .2f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		GLfloat time = (GLfloat)glfwGetTime();
		glUniform1f(timer, time);
		time = 0;
		viewMatrix = camera.GetViewMatrix();
		projMatrix = glm::perspective(camera.Zoom, (float)WIDTH / (float)HEIGHT, 0.1f, 100.0f);
		glm::mat4 modelMatrix;
		modelMatrix = glm::rotate(modelMatrix, time * 100, glm::vec3(0.0f, 0.0f, 1.0f));
		glUniformMatrix4fv(uniModel, 1, GL_FALSE, glm::value_ptr(modelMatrix));
		glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(viewMatrix));
		glUniformMatrix4fv(uniProj, 1, GL_FALSE, glm::value_ptr(projMatrix));

		// CUBE
		glDrawArrays(GL_TRIANGLES, 0, 36);

		glEnable(GL_STENCIL_TEST);
			// FLOOR
			/*glStencilFunc(GL_ALWAYS, 1, 0xFF);
			glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
			glStencilMask(0xFF);
			glDepthMask(GL_FALSE);
			glClear(GL_STENCIL_BUFFER_BIT);

			glDrawArrays(GL_TRIANGLES, 36, 6);
			
			// CUBE REFLECTION
			glStencilFunc(GL_EQUAL, 1, 0xFF);
			glStencilMask(0x00);
			glDepthMask(GL_TRUE);

			modelMatrix = glm::scale(glm::translate(modelMatrix, glm::vec3(0, 0, -1)), glm::vec3(1, 1, -1));
			glUniformMatrix4fv(uniModel, 1, GL_FALSE, glm::value_ptr(modelMatrix));

			glUniform3f(uniColor, 0.3f, 0.3f, 0.3f);

			glUniform3f(uniColor, 0.3f, 0.3f, 0.3f);
				glDrawArrays(GL_TRIANGLES, 0, 36);
			glUniform3f(uniColor, 1.0f, 1.0f, 1.0f);*/
		glDisable(GL_STENCIL_TEST);

		// Bind default framebuffer and draw contents of our framebuffer
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glBindVertexArray(vaoQuad);
		glDisable(GL_DEPTH_TEST);
		glUseProgram(screenShaderProgram);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, texColorBuffer);

		glDrawArrays(GL_TRIANGLES, 0, 6);

		glfwSwapBuffers(window);
	}

	glDeleteRenderbuffers(1, &rboDepthStencil);
	glDeleteTextures(1, &texColorBuffer);
	glDeleteFramebuffers(1, &frameBuffer);

	glDeleteTextures(1, &texKitten);
	glDeleteTextures(1, &texPuppy);

	glDeleteProgram(screenShaderProgram);
	glDeleteShader(screenFragmentShader);
	glDeleteShader(screenVertexShader);

	glDeleteProgram(sceneShaderProgram);
	glDeleteShader(sceneFragmentShader);
	glDeleteShader(sceneVertexShader);

	glDeleteBuffers(1, &vboCube);
	glDeleteBuffers(1, &vboQuad);

	glDeleteVertexArrays(1, &vaoCube);
	glDeleteVertexArrays(1, &vaoQuad);

	glfwTerminate();
}
示例#20
0
int main( void )
{
	initGLFW();
	initWindow();
	initGLEW();
	initKeyboard();
	
	// Dark blue background
	glClearColor(0.0f, 0.0f, 0.4f, 0.0f);

	int size = 5;
	float* map = generateHeightMap(size);
	printf("generated map\n" );
	std::vector<glm::vec3> terrain;
	mapHeightsToPoints(terrain, map, size);
	printf("mapped to points\n");
	// GLuint* indices = generateIndices(terrain, size);

	uint terrainVertexAmount = size* size * 3;
	uint indiceAmount = 3 * (1 << size);

	for(int i = 0; i < terrain.size(); ++i){
		printf("[%f, %f, %f]\n", terrain[i].x, terrain[i].y, terrain[i].z);
	}

	printf("vertices %d\n", terrainVertexAmount);

	GLuint VertexArrayID = newVertexArray();

	// Create and compile our GLSL program from the shaders
	GLuint programID = LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" );
	printf("loaded\n");
	initMatrices(programID);

	
	GLuint vertexbuffer = newVertexBuffer(terrainVertexAmount, &terrain);
	
	double lastTime = glfwGetTime();
 	int nbFrames = 0;
 	printf("loop\n");


 	initDepth();
	do{

		// Clear the screen
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		// Use our shader
		glUseProgram(programID);
		
		// TODO
		// recalculateMatrices();

		// Send our transformation to the currently bound shader, 
		// in the "MVP" uniform
		glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);

		// 1rst attribute buffer : vertices
		bindVertexBuffer(vertexbuffer);

		// Draw the triangle !
		glDrawArrays(GL_TRIANGLE_FAN, 0, terrainVertexAmount); // 3 indices starting at 0 -> 1 triangle

		glDisableVertexAttribArray(0);

		// Swap buffers
		glfwSwapBuffers(window);
		glfwPollEvents();


		// measureTime(lastTime, &nbFrames);

	} // Check if the ESC key was pressed or the window was closed
	while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
		   glfwWindowShouldClose(window) == 0 );

	// Cleanup VBO
	glDeleteBuffers(1, &vertexbuffer);
	glDeleteVertexArrays(1, &VertexArrayID);
	glDeleteProgram(programID);

	// Close OpenGL window and terminate GLFW
	glfwTerminate();
	// normal** ns = generateNormals(map, size);
	return 0;
}
示例#21
0
void WindowManager::init()
{
	initGLFW();
	initGLEW();
	setGlStates();
}
示例#22
0
//--------------------------------------------------
// Main
int main(int argc, char* argv[])
{
	ErrorLog *log = ErrorLog::getInstance();
	stringstream logStream;

	//maintain an exact frame rate
	const double frameDifferenceTime = 1.0 / FPS * 1000;      // time to render a frame at a specific frame rate (in milliseconds)
	double timeLastFrame = 0;
	double timeThisFrame = 0;
	double timeDifference = 0;


	if (!initSDL())
	{
		logStream << "error initializing SDL!!" << endl;
		log->reportError(logStream.str());
		return -1;
	}

	if (!initOpenGL())
	{
		logStream << "error initializing OpenGL!!" << endl;
		log->reportError(logStream.str());
		return -1;
	}

	if (!initGLEW())
	{
		logStream << "error initializing GLEW!!" << endl;
		log->reportError(logStream.str());
		return -1;
	}

	logStream.str("");
	logStream << "Using GLEW Version: " << glewGetString(GLEW_VERSION) << endl << endl;
	log->reportError(logStream.str());

	if (GLEW_VERSION_2_0)
	{
		logStream.str("");
		logStream << "OpenGL 2.0 available" << endl << endl;
		log->reportError(logStream.str());
	}
	else
	{
		logStream.str("");
		logStream << "OpenGL 2.0 not available" << endl << endl;
		log->reportError(logStream.str());
	}

	// check if necessary extensions to run the shader are available
	if (!glewIsSupported("GL_ARB_shader_objects GL_ARB_vertex_shader GL_ARB_fragment_shader GL_ARB_vertex_program"))
	{
		logStream.str("");
		logStream << "one or more extensions to run the shader are not available!!" << endl;
		log->reportError(logStream.str());
		return -1;
	}

	// check if necessary extensions to run cube mapping are available
	if (!GL_ARB_texture_cube_map)
	{
		logStream.str("");
		logStream << "GL_ARB_texture_cube_map extension not available!!" << endl;
		log->reportError(logStream.str());
		return -1;
	}

	input = new Input();
	try
	{
		scene = new Scene(input);
	}
	catch (Exception e)
	{
		logStream.str("");
		logStream << e.getMessage() << endl;
		log->reportError(logStream.str());
		return -1;
	}

	while (!input->keyPressed(SDLK_ESCAPE))
	{
		timeThisFrame = SDL_GetTicks();                                     // get time in ms
		timeDifference = timeThisFrame - timeLastFrame;

		// if time difference between this and the last frame is greater
		// or equal than the specified frame time difference then render
		// the frame
		if (timeDifference >= frameDifferenceTime)
		{
			timeLastFrame = timeThisFrame;
			input->update();							// Process any ocuring events
			scene->update(timeDifference);
			scene->render();							// Draw your graphics
		}
		else                        // if the timedifference is smaller, than sleep for a specified time
		{
			int timeToSleep = (int) (frameDifferenceTime - timeDifference);           // in milliseconds

			// the following stuff is a little bit ugly but there are different
			// sleep functions for Unix and Windows systems
#ifdef WIN32
			Sleep(timeToSleep);
#else
			usleep(1000 * timeToSleep);
#endif
		}
	}

	delete input;
	delete scene;
	SDL_Quit();

	return 0;
}
示例#23
0
		GLWindow(eq::Window* window, Widget* widget) :
			eq::GLWindow(window), widget(widget)
		{
			makeCurrent();
			initGLEW();
		}
示例#24
0
bool COpenGLControl::initOpenGL(HINSTANCE hInstance, HWND* a_hWnd, int iMajorVersion, int iMinorVersion, void (*a_initScene)(LPVOID), void (*a_renderScene)(LPVOID), void(*a_releaseScene)(LPVOID), LPVOID lpParam)
{
	if(!initGLEW(hInstance))return false;

	hWnd = a_hWnd;
	hDC = GetDC(*hWnd);

	bool bError = false;
	PIXELFORMATDESCRIPTOR pfd;

	if(iMajorVersion <= 2)
	{
		memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
		pfd.nSize		= sizeof(PIXELFORMATDESCRIPTOR);
		pfd.nVersion   = 1;
		pfd.dwFlags    = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
		pfd.iPixelType = PFD_TYPE_RGBA;
		pfd.cColorBits = 32;
		pfd.cDepthBits = 32;
		pfd.iLayerType = PFD_MAIN_PLANE;
 
		int iPixelFormat = ChoosePixelFormat(hDC, &pfd);
		if (iPixelFormat == 0)return false;

		if(!SetPixelFormat(hDC, iPixelFormat, &pfd))return false;

		// Create the old style context (OpenGL 2.1 and before)
		hRC = wglCreateContext(hDC);
		if(hRC)wglMakeCurrent(hDC, hRC);
		else bError = true;
	}
	else if(WGLEW_ARB_create_context && WGLEW_ARB_pixel_format)
	{
		const int iPixelFormatAttribList[] =
		{
			WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
			WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
			WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
			WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
			WGL_COLOR_BITS_ARB, 32,
			WGL_DEPTH_BITS_ARB, 24,
			WGL_STENCIL_BITS_ARB, 8,
			0 // End of attributes list
		};
		int iContextAttribs[] =
		{
			WGL_CONTEXT_MAJOR_VERSION_ARB, iMajorVersion,
			WGL_CONTEXT_MINOR_VERSION_ARB, iMinorVersion,
			WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
			0 // End of attributes list
		};

		int iPixelFormat, iNumFormats;
		wglChoosePixelFormatARB(hDC, iPixelFormatAttribList, NULL, 1, &iPixelFormat, (UINT*)&iNumFormats);

		// PFD seems to be only redundant parameter now
		if(!SetPixelFormat(hDC, iPixelFormat, &pfd))return false;

		hRC = wglCreateContextAttribsARB(hDC, 0, iContextAttribs);
		// If everything went OK
		if(hRC) wglMakeCurrent(hDC, hRC);
		else bError = true;

	}
	else bError = true;
	
	if(bError)
	{
		// Generate error messages
		char sErrorMessage[255], sErrorTitle[255];
		sprintf(sErrorMessage, "OpenGL %d.%d is not supported! Please download latest GPU drivers!", iMajorVersion, iMinorVersion);
		sprintf(sErrorTitle, "OpenGL %d.%d Not Supported", iMajorVersion, iMinorVersion);
		MessageBox(*hWnd, sErrorMessage, sErrorTitle, MB_ICONINFORMATION);
		return false;
	}

	renderScene = a_renderScene;
	initScene = a_initScene;
	releaseScene = a_releaseScene;

	if(initScene != NULL)initScene(lpParam);

	return true;
}