コード例 #1
0
ファイル: engine.cpp プロジェクト: gladky/Four-stroke-engine
int main(int argc, char** argv)
{

	int width      = 800, height   = 600;
	int redBits    = 8,   greenBits = 8,  blueBits    = 8;
	int alphaBits  = 8,   depthBits = 24, stencilBits = 8;

   glutInit( &argc, argv );

   glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL );					//tryb wyswietlania (podwojne buforowanie|RGB|zbuforem glebokosci)

   glutInitWindowPosition( windowPosX, windowPosY );							//polozenie okna
   glutInitWindowSize( 854, 480 );												//rozmiar okna

   glutCreateWindow( "four stroke engine");

   glutDisplayFunc( display );													//rejestracja funkcji rysujacej zawartosc okna - display funkcja uzytkownika
   glutReshapeFunc( reshape );													//rejestracja funkcji zminieniajacej rozmiar okna - reshape funk uzytkownika
   glutKeyboardFunc(keyFunc);
   glutSpecialFunc(specialKeys);
   glutIdleFunc( display);


   glfwInit();


   init();																		//oswietlenie i cieniowanie

   //wchar_t imageFilename[] = L"image.jpg";  // Specify filename
	textureHandle = ilutGLLoadImage((wchar_t *)"ground.jpg");
	std::cout << "Image width         : " << ilGetInteger(IL_IMAGE_WIDTH)          << std::endl;
	std::cout << "Image height        : " << ilGetInteger(IL_IMAGE_HEIGHT)         << std::endl;
	std::cout << "Image bits per pixel: " << ilGetInteger(IL_IMAGE_BITS_PER_PIXEL) << std::endl;

	textureSideHandle = ilutGLLoadImage((wchar_t *)"side.jpg");
	std::cout << "Image width         : " << ilGetInteger(IL_IMAGE_WIDTH)          << std::endl;
	std::cout << "Image height        : " << ilGetInteger(IL_IMAGE_HEIGHT)         << std::endl;
	std::cout << "Image bits per pixel: " << ilGetInteger(IL_IMAGE_BITS_PER_PIXEL) << std::endl;

	textureTopHandle = ilutGLLoadImage((wchar_t *)"top.jpg");

	std::cout << "Image width         : " << ilGetInteger(IL_IMAGE_WIDTH)          << std::endl;
	std::cout << "Image height        : " << ilGetInteger(IL_IMAGE_HEIGHT)         << std::endl;
	std::cout << "Image bits per pixel: " << ilGetInteger(IL_IMAGE_BITS_PER_PIXEL) << std::endl;
 

   glutMainLoop();																//rozpoczyna przetwarzanie zdarzen przez system

   return 0;
}
コード例 #2
0
GLuint TextureManager::getTextureFullpath(const std::string filename, const std::string imageURL)
{

    if (textures.find(filename)!= textures.end()) {
        return textures[filename];
    } else {

#ifdef USE_DEVIL
        GLuint tex = ilutGLLoadImage((char *)imageURL.c_str());
#else
        int width, height;

        uint tex = SOIL_load_OGL_texture_size(
                       imageURL.c_str(),
                       SOIL_LOAD_AUTO,
                       SOIL_CREATE_NEW_ID,

                       //SOIL_FLAG_POWER_OF_TWO
                       //  SOIL_FLAG_MIPMAPS
                       SOIL_FLAG_MULTIPLY_ALPHA
                       //|  SOIL_FLAG_COMPRESS_TO_DXT
                       //| SOIL_FLAG_DDS_LOAD_DIRECT
                       ,&width,&height);

#endif
        textures[filename]=tex;
        widths[filename]=width;
        heights[filename]=height;
        return tex;


    }
}
コード例 #3
0
ファイル: eAttribute.cpp プロジェクト: cliclcly/oxalo
// ------------------------------------
TexAttr::TexAttr(std::string path) :
// ------------------------------------
	Attribute(EATTR_TEXTURE)
{
	m_texture = ilutGLLoadImage((char*)path.c_str());
	m_tex_coord_x1=0;
	m_tex_coord_x2=1;
	m_tex_coord_y1=0;
	m_tex_coord_y2=1;
}	
コード例 #4
0
ファイル: eAttribute.cpp プロジェクト: cliclcly/oxalo
// ------------------------------------
TexAttr::TexAttr() :
// ------------------------------------
	Attribute(EATTR_TEXTURE)
{
	m_texture = ilutGLLoadImage((char*)"Textures/default.png");
	m_tex_coord_x1=0;
	m_tex_coord_x2=1;
	m_tex_coord_y1=0;
	m_tex_coord_y2=1;
}
コード例 #5
0
ファイル: eAnimationObject.cpp プロジェクト: cliclcly/oxalo
// ------------------------------------
GLuint AnimationObject::getGUID()
// ------------------------------------
{
    if (m_animID==0)
    {
        //printf("loading texture: %s\n",m_path.c_str());
        m_animID = ilutGLLoadImage((char*)m_path.c_str());
        //printf("loading texture finished: %d\n",m_animID);
    }
    //printf("returning %d\n",m_animID);
    return m_animID;
}
コード例 #6
0
void readTextures(scene_data* scene, const boost::property_tree::ptree& pt)
{
	boost::property_tree::ptree::const_iterator iter = pt.begin();
	for (; iter != pt.end(); ++iter)
	{
		std::string name = iter->first;
		std::string filename = iter->second.get_value<std::string>();
		GLuint image = ilutGLLoadImage((wchar_t*)filename.c_str());
		ILenum error = ilGetError();
		printf("%s\n", iluErrorString(error));
		scene->textures[name] = image;
	}
}
コード例 #7
0
bool CSprite::LoadTexture(char* filename)
{
	Engine()->PushContext();

	// TODO: Move this into a separate class

	if ( !glIsEnabled( GL_TEXTURE_RECTANGLE_NV ) ) 
	{
		m_iTexture = ilutGLLoadImage( filename );

		if (ilGetError() != IL_NO_ERROR)
			return false;

		m_iWidth = ilGetInteger( IL_IMAGE_WIDTH );
		m_iHeight = ilGetInteger( IL_IMAGE_HEIGHT );

	}
	else
	{
		ILuint texid;

		ilGenImages(1, &texid);
		ilBindImage(texid);
		ilLoadImage( filename );

		ILenum Error = ilGetError();

		if ( Error != IL_NO_ERROR )
		{
			sqstd_printcallstack( Sqrat::DefaultVM::Get() );
			std::stringstream st; st << "DevIL Error: " << iluErrorString(Error) << std::endl;
			Engine()->Debug( st.str() );
			return false;
		}

		m_iWidth = ilGetInteger( IL_IMAGE_WIDTH );
		m_iHeight = ilGetInteger( IL_IMAGE_HEIGHT );

		ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
		glGenTextures(1, &m_iTexture);
		glBindTexture(GL_TEXTURE_RECTANGLE_NV, m_iTexture);
		glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, ilGetInteger(IL_IMAGE_BPP), m_iWidth,
		 m_iHeight, 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,
		 ilGetData());
	}

	//Engine()->PopContext();
	return true;
}
コード例 #8
0
/* function main()
* Description:
*  - this is the main function
*  - does initialization and then calls glutMainLoop() to start the event handler
*/
int main(int argc, char **argv)
{
	/* initialize the window and OpenGL properly */
	glutInit(&argc, argv);
	glutInitWindowSize(windowWidth, windowHeight);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
	glutCreateWindow("Supercool dope title game");

	/* set up our function callbacks */
	glutDisplayFunc(DisplayCallbackFunction);
	glutKeyboardFunc(KeyboardCallbackFunction);
	glutKeyboardUpFunc(KeyboardUpCallbackFunction);
	glutReshapeFunc(WindowReshapeCallbackFunction);
	glutMouseFunc(MouseClickCallbackFunction);
	glutMotionFunc(MouseMotionCallbackFunction);
	glutPassiveMotionFunc(MousePassiveMotionCallbackFunction);
	glutTimerFunc(1, TimerCallbackFunction, 0);

	/* Call some OpenGL parameters */
	glEnable(GL_CULL_FACE);
	//glFrontFace(GL_CCW);
	//glCullFace(GL_BACK);
	glEnable(GL_DEPTH_TEST);

	/* Turn on the lights! */
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_COLOR_MATERIAL);
	glShadeModel(GL_SMOOTH);
	///glShademodel(GL_SMOOTH);

	/* Init Image Library */
	glEnable(GL_TEXTURE_2D);
	//replace the parameters in loadObj with what you want to load
	loadObj("C:\\Users\\100550931\\Documents\\intro to graphics tutorials\\Tutorial3Package\\Tutorial3Package\\Tutorial1IntroGraphics\\obj.txt");
	ilInit();
	iluInit();
	ilutRenderer(ILUT_OPENGL);

	/* Load a texture */
	textureHandle = ilutGLLoadImage("..//img//win.png");
	glBindTexture(GL_TEXTURE_2D, textureHandle);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	glBindTexture(GL_TEXTURE_2D, NULL);

	/* start the event handler */
	glutMainLoop();
	return 0;
}
コード例 #9
0
ファイル: Ez2DSDebugDraw.c プロジェクト: catdawg/Ez2DS
Texture* 
getTextureID(char* path)  {
    Texture *s;
    HASH_FIND_STR( pathToTexTable, path, s );  /* s: output pointer */
    if(s == NULL)  {
        s = (Texture*)malloc(sizeof(Texture));
        s->path = (char*)malloc(strlen(path)*sizeof(char));
        strcpy(s->path, path);
        s->textureID = ilutGLLoadImage(path);
        s->width = ilGetInteger(IL_IMAGE_WIDTH);
        s->height = ilGetInteger(IL_IMAGE_HEIGHT);
        HASH_ADD_KEYPTR( hh, pathToTexTable, s->path, strlen(s->path), s );
    }
    return s;
}
コード例 #10
0
ファイル: eAttribute.cpp プロジェクト: cliclcly/oxalo
// ------------------------------------
TexAttr::TexAttr(std::string objType, COLOR color) :
// ------------------------------------
	Attribute(EATTR_TEXTURE)
{
	std::string path = "Textures/";
	path+= objType;
	path+= "/";
	if (color >= 0)
	{
		path+= EngineClass::colorString[color];
		path+="/";
	}
	path+="default.png";
	m_texture = ilutGLLoadImage((char*)path.c_str());
	m_tex_coord_x1=0;
	m_tex_coord_x2=1;
	m_tex_coord_y1=0;
	m_tex_coord_y2=1;
}	
コード例 #11
0
ファイル: objLoader.cpp プロジェクト: Lumbendil/Cara-Gestual
int COBJModel::LoadTexture2(const char szFileName[_MAX_PATH])
{
	////////////////////////////////////////////////////////////////////////
	// Load a texture and return its ID
	////////////////////////////////////////////////////////////////////////

	FILE *file=NULL;
	int errno;
	unsigned int iTexture = 0;

	
// Open the image file for reading
// file=fopen(filename,"r");					// Funció Visual Studio 6.0
   errno=fopen_s(&file,szFileName,"r");			// Funció Visual 2005

// If the file is empty (or non existent) print an error and return false
// if (file == NULL)
   if (errno!=0)
 {
//	printf("Could not open file '%s'.\n",filename) ;

	 return false ;
 }

// Close the image file
 fclose(file);

// ilutGLLoadImage: Funció que llegeix la imatge del fitxer filename
//				si és compatible amb els formats DevIL/OpenIL (BMP,JPG,GIF,TIF,TGA,etc.)
//				i defineix la imatge com a textura OpenGL retornant l'identificador 
//				de textura OpenGL.
// GetBuffer: Funció de converió d'una variable CString -> char *
iTexture = ilutGLLoadImage((char *) szFileName);

// If execution arrives here it means that all went well. Return true
 
	
	return iTexture;
}
コード例 #12
0
ファイル: Sprite.cpp プロジェクト: Acularius/Pixel-Brother
void Sprite::loadSpriteSheet(const char *filename)
{
	sheet.textureID = ilutGLLoadImage((char*)filename);
	sheet.width = ilGetInteger(IL_IMAGE_WIDTH);
	sheet.height = ilGetInteger(IL_IMAGE_HEIGHT);
}
コード例 #13
0
ファイル: main.cpp プロジェクト: c-day/Warp
int main(int argc, char * argv[])
{
	glutInit(&argc , argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
	glutInitWindowPosition(0 , 0);
	glutInitWindowSize(window_width, window_height);
	glutCreateWindow("Warp");
	glutDisplayFunc(DisplayFunc);
	glutTimerFunc(1000 / 60, TimerFunc, 1000 / 60);
	glutReshapeFunc(ReshapeFunc);
	glutSpecialFunc(SpecialFunc);
	glutKeyboardFunc(KeyboardFunc);
	glutMouseFunc(MouseFunc);
	glutMotionFunc(MotionFunc);
	glutCloseFunc(CloseFunc);
	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
	glEnable(GL_DEPTH_TEST);

	ilInit();
	iluInit();
	ilutInit();
	ilutRenderer(ILUT_OPENGL);

	if (glewInit() != GLEW_OK)
	{
		cerr << "GLEW failed to initialize." << endl;
		return 0;
	}
			
	if (!shader.Initialize("stub.vert", "stub.frag"))
	{
		return 0;
	}

	if (!background.Initialize("back.vert", "back.frag"))
	{
		return 0;
	}


	image_1_handle = ilutGLLoadImage("lotr-scene.jpg");
	image_1_w = ilGetInteger(IL_IMAGE_WIDTH);
	image_1_h = ilGetInteger(IL_IMAGE_HEIGHT);
	
	tex_handle = ilutGLLoadImage("Home-Theater.jpg");
	tex_w = ilGetInteger(IL_IMAGE_WIDTH);
	tex_h = ilGetInteger(IL_IMAGE_HEIGHT);

	left_overlay_handle = ilutGLLoadImage("left-over.jpg");
	right_overlay_handle = ilutGLLoadImage("right-over.jpg");
	left_curtain_handle = ilutGLLoadImage("left-curtain.jpg");

	cout << "Image 1: " << image_1_w << " x " << image_1_h << endl;
	cout << "Background: " << tex_w << " x " << tex_h << endl;
	
	if (!frame.Initialize(glm::ivec2(image_1_w, image_1_h), 1, true))
	{
		cerr << "Frame buffer 1 failed to initialize." << endl;
		return 0;
	}

	cout << "Window Size: " << window_width << " x " << window_height << endl;
	cout << "Frame buffer 1 size: " << frame.size.x << " x " << frame.size.y << endl;

	glutMainLoop();
	return 0;
}
コード例 #14
0
ファイル: imagem.cpp プロジェクト: lndr27/Av2_LeandroAlmeida
ILuint LoadImageTexture(const std::string& filename)
{
    return ilutGLLoadImage(strdup(filename.c_str()));
}
コード例 #15
0
ファイル: CanvasViewport.cpp プロジェクト: dtbinh/canvas
void CanvasViewport::draw() {
	time_t dts = clock() - tCreation;

	//Draw the viewport border
	glLineWidth(3.0);

	glColor4dv( COLOR_VIEWPORT_BORDER );
	glBegin( GL_QUADS );
	  glVertex2i( location.x + 1, location.y );
	  glVertex2i( location.x + width - 1, location.y );
	  glVertex2i( location.x + width - 1, location.y + height );
	  glVertex2i( location.x + 1, location.y + height );
	glEnd();

	//Draw the inside
	dts > TIME_FADE_MS ? glColor3d( 0.0, 0.0, 0.0 ) : glColor4d( 0.0, 0.0, 0.0, 1.0 * (dts / TIME_FADE_MS) );
	glBegin( GL_QUADS );
	  glVertex2i( location.x + BORDER_SIZE, location.y + BORDER_SIZE );
	  glVertex2i( location.x + width - BORDER_SIZE, location.y + BORDER_SIZE );
	  glVertex2i( location.x + width - BORDER_SIZE, location.y + height - BORDER_SIZE );
	  glVertex2i( location.x + BORDER_SIZE, location.y + height - BORDER_SIZE );
	glEnd();

	//glEnable( GL_FOG );
	glFogf( GL_FOG_DENSITY, VIEWPORT_FOG_DENSITY );
	glFogfv( GL_FOG_COLOR, VIEWPORT_FOG_COLOR );

	//Need to change the viewport and scissor params then restore them later
	GLfloat projM[16]; //will also need to restore the projection
	glGetFloatv( GL_PROJECTION_MATRIX, projM );

	glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
	gluPerspective( VIEWPORT_FOVY, (float)width/(float)height, 0, 100 );

	glMatrixMode(GL_MODELVIEW);

	GLint vPort[4];
	glGetIntegerv( GL_VIEWPORT, vPort ); 
	glViewport( location.x + BORDER_SIZE, location.y + BORDER_SIZE, width - BORDER_SIZE * 2, height - BORDER_SIZE * 2 );

	double dt = ( clock() - tPlayback ) / 1000.0;

	if( playing && clip != NULL ) {
		frame = startFrame + clip->getFrameRate() * dt;
		if( frame > endFrame ) {
			if( repeat ) {
				tPlayback = clock();
			}
			frame = endFrame;
		}
	}
	
	glPushMatrix(); {
		cam.applyViewTransform();

		//Draw the floor
		if( glIsList( viewportDLFloor ) ) {
			glCallList( viewportDLFloor );
		} else {
			//Generate the display list and load the texture
			viewportDLFloor = glGenLists(1);
			glNewList(viewportDLFloor, GL_COMPILE_AND_EXECUTE ); {
				glEnable (GL_TEXTURE_2D);
				//glTexEnvi( GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_DECAL );
				glBindTexture( GL_TEXTURE_2D, ilutGLLoadImage( FLOOR_TEXTURE_PATH ));

				glColor4d( 1.0, 1.0, 1.0, 1.0 );

				glBegin( GL_QUADS ); {
					glTexCoord2d( 0.0, 0.0 );
					glVertex3d( -FLOOR_SIZE, FLOOR_DY, -FLOOR_SIZE );
					glTexCoord2d( 0.0, FLOOR_TEXTURE_REPETITIONS );
					glVertex3d( -FLOOR_SIZE, FLOOR_DY, FLOOR_SIZE );
					glTexCoord2d( FLOOR_TEXTURE_REPETITIONS, FLOOR_TEXTURE_REPETITIONS );
					glVertex3d( FLOOR_SIZE, FLOOR_DY, FLOOR_SIZE );
					glTexCoord2d( FLOOR_TEXTURE_REPETITIONS, 0 );
					glVertex3d( FLOOR_SIZE, FLOOR_DY, -FLOOR_SIZE );
				} glEnd();

				glDisable(GL_TEXTURE_2D);

			} glEndList();
		}
		//Draw the model

		glPushMatrix(); {
			glScaled( MODEL_SCALE_FACTOR, MODEL_SCALE_FACTOR, MODEL_SCALE_FACTOR );
			if( clip && !pose ) {
				dt > clip->getRuntime() ? glColor3d( 0.8, 0.8, 0.4 ) : glColor3d( 1.0, 1.0, 0.0 );
			} else {
				glColor3d( 1.0, 1.0, 0.0 );
			}
			glLineWidth( 4.0f );

			if( pose ) {
				pose->draw();
			} else if( clip ) {
				clip->draw( frame );
			}
		} glPopMatrix();
	} glPopMatrix();

	glMatrixMode(GL_PROJECTION); //restore old projection
	glLoadIdentity();
	glMultMatrixf( projM );
	glMatrixMode(GL_MODELVIEW);
	glViewport( vPort[0], vPort[1], vPort[2], vPort[3] );
	glDisable( GL_FOG );

	//Draw model details (text with current frame etc.)
	if( !mDetails || clip == NULL ) {
		return;
	}

	glEnable( GL_SCISSOR_TEST );
	glScissor( location.x + BORDER_SIZE, location.y + BORDER_SIZE, width - BORDER_SIZE * 2, height - BORDER_SIZE * 2 );
	
	std::stringstream mTime;// << clip->getFrameCount();

    mTime << clip->getFrameCount();
	int maxWidth = mTime.str().length();
	mTime.str("");

	mTime.precision( 2 );
	mTime.width( maxWidth );
	mTime.setf(std::ios::fixed);
	mTime.setf(std::ios::right );
	mTime.fill('0');
	mTime << ( frame + 1 ) << " / " << clip->getFrameCount() << " frames ";
	mTime.setf(std::ios::left );
	mTime << " - " << ( (double)( frame + 1 ) / clip->getFrameCount())*clip->getRuntime() << " s";
	mTime.str().length();

	int renderLengthD = glutBitmapLength( MOTION_DETAILS_FONT, (const unsigned char *)mTime.str().c_str() );
	int renderLengthL = glutBitmapLength( MOTION_DETAILS_FONT, (const unsigned char *)clip->getLabel().c_str() );

	glColor4dv( COLOR_INSET_GREY );
	glBegin( GL_QUADS );
	  glVertex2i( location.x + 2* BORDER_SIZE, location.y + 2* BORDER_SIZE );
	  glVertex2i( location.x + 4* BORDER_SIZE + renderLengthD, location.y + 2* BORDER_SIZE );
	  glVertex2i( location.x + 4* BORDER_SIZE + renderLengthD, location.y + 4* BORDER_SIZE + 8 );
	  glVertex2i( location.x + 2* BORDER_SIZE, location.y + 4* BORDER_SIZE + 8 );

      glVertex2i( location.x + 2* BORDER_SIZE, location.y + height - 2 * BORDER_SIZE );
	  glVertex2i( location.x + 4* BORDER_SIZE + renderLengthL, location.y + height - 2* BORDER_SIZE );
	  glVertex2i( location.x + 4* BORDER_SIZE + renderLengthL, location.y + height - 4* BORDER_SIZE - 8 );
	  glVertex2i( location.x + 2* BORDER_SIZE, location.y + height - 4* BORDER_SIZE - 8 );
	glEnd();
	glColor4dv( COLOR_INSET_TEXT );
	drawString( location.x + 3* BORDER_SIZE, location.y + 3* BORDER_SIZE, MOTION_DETAILS_FONT, (char *)mTime.str().c_str() );
	drawString( location.x + 3* BORDER_SIZE, location.y + height - 3* BORDER_SIZE - 8, MOTION_DETAILS_FONT, (char *)clip->getLabel().c_str() );

	glDisable( GL_SCISSOR_TEST );
}