⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 光滑质点无网格法SPH并行计算程序
💻 CPP
字号:
//      ___                       ___           ___           ___       ___     //     /\__\          ___        /\__\         /\  \         /\__\     /\  \.   //    /::|  |        /\  \      /::|  |       /::\  \       /:/  /    /::\  \.  //   /:|:|  |        \:\  \    /:|:|  |      /:/\:\  \     /:/  /    /:/\:\  \. //  /:/|:|__|__      /::\__\  /:/|:|  |__   /:/  \:\  \   /:/  /    /::\~\:\  \.// /:/ |::::\__\  __/:/\/__/ /:/ |:| /\__\ /:/__/_\:\__\ /:/__/    /:/\:\ \:\__\.// \/__/~~/:/  / /\/:/  /    \/__|:|/:/  / \:\  /\ \/__/ \:\  \    \:\~\:\ \/__///       /:/  /  \::/__/         |:/:/  /   \:\ \:\__\    \:\  \    \:\ \:\__\. //      /:/  /    \:\__\         |::/  /     \:\/:/  /     \:\  \    \:\ \/__/  //     /:/  /      \/__/         /:/  /       \::/  /       \:\__\    \:\__\.   //     \/__/                     \/__/         \/__/         \/__/     \/__/    // // =============================================================================//                       Minimalist OpenGL Environment// =============================================================================//// Copyright 2007 Balazs Domonkos// // This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.// // This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.// // You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// Off-screen rendering using MinGLE// FBO is an extra feature of MinGLE. It have to be enabled// before including mingle.h #define MINGLE_ENABLE_FBO// mingle.h should be included before all other// OpenGL headers#include <mingle.h>using namespace MinGLE;#include <GL/glut.h>#include <iostream>// Custom window listener that does the renderingclass SceneRenderer : public WindowListener {	private:		GLuint mTexture;		FramebufferObject *mFbo;		Image *mImage;    public:    	~SceneRenderer() {    		delete mFbo;    		delete mImage;    	}        protected:		virtual void onRegistered() {    		// Create texture    		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);    		glGenTextures(1, &mTexture);    		glBindTexture(GL_TEXTURE_2D, mTexture);    		    		// Set texture parameters			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);      		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);      		      		// Create empty texture      		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, mWindow->getWidth(), mWindow->getHeight(), 0, GL_RGB, GL_FLOAT, 0);      		      		// Create and attach framebuffer object      		mFbo = new FramebufferObject();      		mFbo->Bind();    		glEnable(GL_DEPTH_TEST);      		      		// Attach texture to framebuffer color buffer      		mFbo->AttachTexture(GL_TEXTURE_2D, mTexture, GL_COLOR_ATTACHMENT0_EXT);   			// Validate the FBO after attaching textures and render buffers    		mFbo->IsValid();        		// Disable FBO rendering for now...    		FramebufferObject::Disable();    		    		// Create image    		mImage = new Image();		}				// This method is called when to render		virtual bool onRender() {    		glDisable(GL_TEXTURE_2D);    		// Save the current Draw buffer    		GLint currentDrawbuf;    		glGetIntegerv(GL_DRAW_BUFFER, &currentDrawbuf);			// Render to the FBO    		mFbo->Bind();    					// Clear FBO			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);			// Render a teapot with disabled texturing	    	glutSolidTeapot(0.1);    		// Disable FBO rendering; Render to the window    		FramebufferObject::Disable();    		glDrawBuffer(currentDrawbuf);			// Render a teapot with enabled texturing    		glEnable(GL_TEXTURE_2D);	    	glutSolidCube(0.75);	    	return true;		}				virtual bool onKeyEvent(int key, unsigned modifiers, KeyEventState state) {			switch(key) {				// Save the texture as an image				case KEY_SPACE:					mImage->grabFromTexture2D();					mImage->saveToFile("texture.pfs");					return true;				default:					return false;			}			return false;		}};int main(int argc, char **argv) {	try {    	// Initialize Rendering system    	System::initialize(&argc, argv);		// Create window with default environment (navigator, key handler etc.)		System::createWindowWithDefaultEnv(new SceneRenderer());    	// Setup OpenGL    	glEnable(GL_DEPTH_TEST);    	glShadeModel(GL_SMOOTH);        	GLfloat position[] = { 3.0f, 3.0f, 3.0f, 1.0f };    	GLfloat diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };    	GLfloat specular[] = {1.0f, 1.0f, 1.0f , 1.0f};    	glEnable(GL_LIGHTING);    	glEnable(GL_LIGHT0);    	glLightfv(GL_LIGHT0, GL_POSITION, position);    	glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);    	glLightfv(GL_LIGHT0, GL_SPECULAR, specular);		glClearColor(0.0, 0.5, 0.0, 0.0);				glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);		glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);		glEnable(GL_TEXTURE_GEN_S);		glEnable(GL_TEXTURE_GEN_T);     	// Enter the event handing loop    	System::enterMainLoop();    		} catch(const Exception& e) {		std::cerr << "Error: " << e.mDescription << " (Thrown in " << e.mFile << ':'			<< e.mMethod << " line " << e.mLine << ')' << std::endl;	}    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -