예제 #1
0
void GLCube::SetTexture(GLuint texId)
{
  ClearTexture();

  m_bOwnsTexture = false;
  m_nTexID = texId;
}
예제 #2
0
void GLCube::SetCheckerboard()
{
  ClearTexture();

  // Texture Map Init
  GLubyte img[TEX_W][TEX_H][3]; // after glTexImage2D(), array is no longer needed
  for (int x=0; x<TEX_W; x++) {
    for (int y=0; y<TEX_H; y++) {
      GLubyte c = ((x&16)^(y&16)) ? 255 : 0; // checkerboard
      img[x][y][0] = c;
      img[x][y][1] = c;
      img[x][y][2] = c;
    }
  }

  // Generate and bind the texture
  m_bOwnsTexture = true;
  glGenTextures( 1, &m_nTexID );
  glBindTexture( GL_TEXTURE_2D, m_nTexID );
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
  glTexImage2D( GL_TEXTURE_2D, 0,
                GL_RGB, TEX_W, TEX_H, 0, GL_RGB, GL_UNSIGNED_BYTE, &img[0][0][0] );
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}
예제 #3
0
GLTexture* UIOpenGLTextures::CreateTexture(QSize ActualSize, bool UsePBO,
                                           uint Type, uint DataType,
                                           uint DataFmt, uint InternalFmt,
                                           uint Filter, uint Wrap)
{
    if (!Type)
        Type = m_defaultTextureType;

    QSize totalsize = GetTextureSize(Type, ActualSize);

    GLuint tex;
    glGenTextures(1, &tex);
    glBindTexture(Type, tex);

    if (tex)
    {
        GLTexture *texture = new GLTexture(tex);
        texture->m_type        = Type;
        texture->m_dataType    = DataType;
        texture->m_dataFmt     = DataFmt;
        texture->m_internalFmt = InternalFmt;
        texture->m_size        = totalsize;
        texture->m_actualSize  = ActualSize;
        texture->m_dataSize    = GetBufferSize(ActualSize, DataFmt, DataType);
        texture->m_internalDataSize = GetBufferSize(totalsize, InternalFmt, GL_UNSIGNED_BYTE);
        SetTextureFilters(texture, Filter, Wrap);
        ClearTexture(texture);
        if (UsePBO)
            CreatePBO(texture);
        CreateVBO(texture);

        m_textures.insert(tex, texture);

        return texture;
    }

    return NULL;
}
예제 #4
0
void game_on_draw( double gameTime ) {
	CATCH_GL_ERROR("OnEntry to game_on_draw()");
	double drawStart = glfwGetTime();
	drawStart = 0.0f;
	const float yAngle = 0.0f;
	const float xAngle = 0.2f;

	float sy = sin( yAngle );
	float cy = cos( yAngle );
	float sx = sin( xAngle );
	float cx = cos( xAngle );
	const float dist = 20.0f;
	gCamPos = Vec3( cx * sy * dist, sx * dist, cx * cy * dist );

	DefaultShaderProgram.Use(true);
	CATCH_GL_ERROR("On UseDefaultShader");

	GLfloat mvmat[16];

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_GEQUAL);
	glDisable(GL_BLEND);//glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	Vec3 camUp = Vec3(0,1,0);

	const float fov = 1.0f;
	gProjectionMat = Mat44Perspective( fov, (float)win_width / (float)win_height, 0.1f, 100.0f);
	g_fLastPerspectiveValues[0] = gProjectionMat.x.x;
	g_fLastPerspectiveValues[1] = gProjectionMat.y.y;
	gCameraMat = Mat44LookAt( gCamPos, gCamAim, camUp);
	gCamProj = gCameraMat * gProjectionMat;// * gCameraMat;
	memset(mvmat, 0, sizeof(mvmat)); mvmat[0*4+0] = mvmat[1*4+1] = mvmat[2*4+2] = mvmat[3*4+3] = 1;
	CATCH_GL_ERROR("miscPreDraw");

	GLShader *current = GLShader::Current();
	if( current ) {
		glUniformMatrix4fv(GLShader::Current()->projLocation, 1, false, gCamProj);
		CATCH_GL_ERROR("UploadProj");
	} else {
		printf( "No current shader!\n" );
	}

	glClearColor( 0.4f,0.4f,0.5f, 1.0f );
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	Vec4 point;
	point.x = 0.6f;
	point.y = 2.0f;
	point.z = 0.26;
	point.w = 1.0f;

	// the elements of space
	current = GLShader::Current();
	if( current ) {
		mvmat[3*4+0] = 0.0f; mvmat[3*4+2] = 0.0f;
		glUniformMatrix4fv(GLShader::Current()->mvLocation, 1, false, mvmat );
		CATCH_GL_ERROR("ModelMatrix");
	} else {
		printf( "No current shader\n" );
	}

	if( gWireframeMode ) {
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	}

	GLuint textureID;

	glDisable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	CATCH_GL_ERROR("Draw");

	glEnable(GL_BLEND);

	DefaultShaderProgram.Use();
	glDepthMask(GL_TRUE);

	CATCH_GL_ERROR("Pre-Default Shader");
	DefaultShaderProgram.Use();
	CATCH_GL_ERROR("Setting Default Shader");

	glActiveTexture(GL_TEXTURE0);
	SetTexture( "cursor", 0 );

	glEnable(GL_ALPHA_TEST);
	glEnable(GL_TEXTURE_2D);
	glMatrixMode(GL_MODELVIEW);
	if( true ) {
		for( ThingList::iterator i = gWorldThings.begin(); i != gWorldThings.end(); ++i ) {
			if( i->texture.c_str()[0] ) {
				SetTexture(i->texture.c_str(),0);
				Mat44 modelMat = Translation(i->position);
				modelMat.Rotation(i->angle, Vec3(0,0,1));
				modelMat.Scale(i->scale);
				glUniformMatrix4fv(GLShader::Current()->mvLocation, 1, false, modelMat );
				i->mesh->DrawTriangles();
			}
		}

		// do cursor
		extern Vec2 mouseScreenPos;
		Vec3 mouseRay = RayFromCam( gCameraMat, mouseScreenPos, GLPerspectiveFactorX(), GLPerspectiveFactorY() );
		Vec3 rayHit = RayHitsPlaneAt( gCamPos, mouseRay, Vec4( 0, 0, 1, 0 ) );

		Vec3 mpos = Vec3( rayHit.x, rayHit.y, 0.001f );
		ClearTexture();

		glUniformMatrix4fv(GLShader::Current()->mvLocation, 1, false, Translation(mpos) );
		//extern BadMesh *gMonkeyMesh;
		//if( gMonkeyMesh ) {
			//gMonkeyMesh->DrawTriangles();
		//}
	}

	//glDisable(GL_DEPTH_TEST);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	float w = float(win_width / 2);
	float h = float(win_height / 2);
	gProjectionMat = Mat44Orthographic( 0, win_width, win_height, 0, -1, 1 );
	glUniformMatrix4fv(GLShader::Current()->projLocation, 1, false, gProjectionMat );
	CATCH_GL_ERROR("Proj");

	if( 1 ) {
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		glTranslatef(0.0f, 0.0f, 0.1f);
		glScalef( 8.0f, 8.0f, 1.0f );

		char buffer[128];
		sprintf( buffer, "%ims", (int)(gameTime * 1000) );
		FontPrint( buffer );
	}

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glColor4f(1.0f,1.0f,1.0f,0.9f);
	glScalef(1.0f,1.0f,0.1f);
	glRotatef(drawStart*45.0f, 0.0f,1.0f,0.0f );
	glGetFloatv(GL_MODELVIEW_MATRIX,mvmat);
	//glUniformMatrix4fv(mvLocation, 1, false, mvmat );
	glUniformMatrix4fv(GLShader::Current()->mvLocation, 1, false, mvmat );
	CATCH_GL_ERROR("ModelMatrix");
	SetTexture( "cursor", 0 );

	//printf( "Bound the shader to 0, not %i\n", textureID );
	draw_ZNEG();
	CATCH_GL_ERROR("DrawZNeg");

	glLoadIdentity();
	glTranslatef(8+16-w,8+16-h,0);
	glScalef(16.0f,16.0f,0.1f);
	glGetFloatv(GL_MODELVIEW_MATRIX,mvmat);
	//glUniformMatrix4fv(mvLocation, 1, false, mvmat );
	CATCH_GL_ERROR("ModelView");
	//draw_ZNEG();

	CATCH_GL_ERROR("EndOfDisplay");
}