Ejemplo n.º 1
0
void NStar::Draw(NCamera* View)
{
    GenerateBuffers();
    if (Texture == NULL || GetColor().w == 0 || Shader == NULL)
    {
        return;
    }
    glUseProgram(Shader->GetID());
    glActiveTexture(GL_TEXTURE0);
    if (Texture != NULL)
    {
        glBindTexture(GL_TEXTURE_2D,Texture->GetID());
    }
    glUniform1i(TextureLoc,0);
    glUniformMatrix4fv(MatrixLoc,1,GL_FALSE,glm::value_ptr(GetModelMatrix()));
    glUniform4fv(ColorLoc,1,&(GetColor()[0]));
    glEnableVertexAttribArray(Shader->GetVertexAttribute());
    glBindBuffer(GL_ARRAY_BUFFER,Buffers[0]);
    glVertexAttribPointer(Shader->GetVertexAttribute(),2,GL_FLOAT,GL_FALSE,0,NULL);
    glEnableVertexAttribArray(Shader->GetUVAttribute());
    glBindBuffer(GL_ARRAY_BUFFER,Buffers[1]);
    glVertexAttribPointer(Shader->GetUVAttribute(),2,GL_FLOAT,GL_FALSE,0,NULL);
    
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_TEXTURE_2D);
    glDrawArrays(GL_QUADS,0,Verts.size());
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);

    glDisableVertexAttribArray(Shader->GetVertexAttribute());
    glDisableVertexAttribArray(Shader->GetUVAttribute());
    glUseProgram(0);
}
Ejemplo n.º 2
0
Renderer14::Renderer14(int width, int height): RenderingEngine(width, height)
{
    glViewport(0, 0, width, height);

    PrepareProgram();
    LoadTexture();
    SetupUniforms();
    GenerateBuffers();
}
Ejemplo n.º 3
0
	ErrorType SoundStream::Open(Int numBuffers) {
		Close();
		ErrorType error = GenerateBuffers(numBuffers);
		if (error) {
			Close();
			return Error::Throw(error, String("[%s(%d)]",
				FastFunctionName, numBuffers));
		}
		return kErrorNone;
	}
Ejemplo n.º 4
0
void LoadNextPiece() {
	Piece np = pieces[nextPiece];
	np.Reset();

	GenerateBuffers(np, vbo_cube_next, ibo_cube_next);

	translate_next = glm::translate(glm::mat4(1.0f), glm::vec3(np.getX() - 10, np.getY() - 1, np.getZ()));

	glwriter->Write("Next Piece:", 12, -0.95, 0.95);
	glwriter->Draw();

}
Ejemplo n.º 5
0
void InitWell() {
	if (well != 0) {
		delete well;
		well = 0;
	}
	well = new Well(10, 14, 0.0, 0.0, 0.0);

	MakePieces();
	nextPiece = PickRandomPiece();
	PickPiece();

	std::vector<float> grid;
	well->MakeGrid(grid);
	GenerateArrayBuffer(grid, vbo_grid);
	GenerateBuffers(*cp, vbo_cube, ibo_cube_elements);
	GenerateBuffers(*well, vbo_fixed, ibo_fixed);
	glutPostRedisplay();

	glutTimerFunc(100, timerCallBack, 0);
	isGameOver = false;
}
Ejemplo n.º 6
0
void NavigationLine::Render(RenderPhase phase)
{
	if (phase != Renderable::Render_Geometry)
		return;
	if (!m_loaded)
		return;
	if (m_needsUpdate)
		GenerateBuffers();
	if (!m_vertexBuffer)
		return;

	D3DXMATRIX world;
	D3DXMatrixIdentity(&world);
	g_pDevice->SetTransform(D3DTS_WORLD, &world);

	D3DXMATRIX view, proj, mWVP, mWV;
	g_pDevice->GetTransform(D3DTS_VIEW, &view);
	g_pDevice->GetTransform(D3DTS_PROJECTION, &proj);

	mWV = world * view;
	mWVP = world * view * proj;

	// We will not be using a viewing transformation, so the view matrix will be identity.
	m_effect->SetMatrix("mWV", &mWV);
	m_effect->SetMatrix("mWVP", &mWVP);

	UINT passes = 0;
	m_effect->Begin(&passes, 0);

	for (int iPass = 0; iPass < passes; iPass++)
	{
		m_effect->BeginPass(iPass);

		g_pDevice->SetVertexDeclaration(m_vDeclaration);
		g_pDevice->SetStreamSource(0, m_vertexBuffer, 0, sizeof(TVertex));

		// render
		for (auto& cmd : m_commands)
		{
			g_pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,
				cmd.StartVertex, cmd.PrimitiveCount);
		}

		m_effect->EndPass();
	}
	m_effect->End();
}
Ejemplo n.º 7
0
	void Terrain::DrawGeometry()
	{
		auto device = Device::GetInstance();
		if (this->changed)
		{
			GenerateBuffers();

			this->changed = false;
		}

		device->SetVertexFormat(this->vertexFormat);
		device->SetVertexBuffer(this->vb.Get(), sizeof(TerrainVertex), 0);
		device->SetIndexBuffer(this->ib.Get());
		device->GetRenderState()->GetCurrentShader()->CommitChanges();
		device->DrawIndexed(PrimitiveType::TRIANGLE_LIST,
			(this->xResolution - 1) * (this->yResolution - 1) * 6,
			0, 0);
	}
Ejemplo n.º 8
0
 Terrain::Terrain(const char* filename) {
     // Load height map from file
     int components;
     unsigned char* data;
     data = stbi_load(filename, &width, &height, &components, 0);
 
     if (data == NULL)
         Log() << "Couldn't load image: " << filename << "\n";
 
     // Convert height map to float.
     heightMap = new float*[width];
     normals = new glm::vec3*[width];
     tangents = new glm::vec3*[width];
     for (int i = 0; i < width; i++) {
         heightMap[i] = new float[height];
         normals[i] = new glm::vec3[height];
         tangents[i] = new glm::vec3[height];
     }
 
     for (int x = 0; x < width; x++) {
         for (int y = 0; y < height; y++) {
             heightMap[x][y] = data[(x + y*width)*components] / 256.f;
         }
     }
 
     stbi_image_free(data);
 
     Filter3x3();
     CalculateNormals();
 
     GenerateVertices();
     GenerateIndices();
 
     for (int i = 0; i < width; i++) {
         delete[] normals[i];
         delete[] tangents[i];
     }
     delete[] normals;
     delete[] tangents;
 
     GenerateBuffers();
     GenerateVertexArray();
 }
Ejemplo n.º 9
0
void NText::DrawMask(NCamera* View)
{
    if (GetColor().w == 0)
    {
        return;
    }
    GenerateBuffers();
    if (MaskShader == NULL)
    {
        glEnableClientState(GL_VERTEX_ARRAY);
        glBindBuffer(GL_ARRAY_BUFFER,Buffers[2]);
        glVertexPointer(2,GL_FLOAT,0,NULL);

        glMatrixMode(GL_PROJECTION);
        glLoadMatrixf(&View->GetPerspMatrix()[0][0]);
        glMatrixMode(GL_MODELVIEW);
        glm::mat4 MVP = View->GetViewMatrix();
        glLoadMatrixf(&MVP[0][0]);

        glColor4f(1,1,1,1);
        glDrawArrays(GL_QUADS,0,Mask.size());

        glDisableClientState(GL_VERTEX_ARRAY);
        return;
    }
    glUseProgram(MaskShader->GetID());
    glm::mat4 MVP = View->GetOrthoMatrix()*View->GetViewMatrix()*GetModelMatrix();
    glUniformMatrix4fv(MMatrixLoc,1,GL_FALSE,&MVP[0][0]);
    glUniform4f(MColorLoc,0,0,0,0);
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER,Buffers[2]);
    glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,NULL);
    
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDrawArrays(GL_QUADS,0,Mask.size());
    glDisable(GL_BLEND);

    glDisableVertexAttribArray(0);
    glUseProgram(0);
}
Ejemplo n.º 10
0
void NButton::Draw(NCamera* View)
{
    //Make sure we have our buffers generated.
    GenerateBuffers();
    //If we don't have a texture, are invisible, or our shader doesn't exist, don't draw!
    if (Texture == NULL || GetColor().w == 0 || Shader == NULL)
    {
        return;
    }
    glUseProgram(Shader->GetID());
    glActiveTexture(GL_TEXTURE0);
    //Make sure we have a texture before we try to call a member in it.
    if (Texture != NULL)
    {
        glBindTexture(GL_TEXTURE_2D,Texture->GetID());
    }
    glUniform1i(TextureLoc,0);
    //Generate our matrix to send to the GPU.
    glm::mat4 MVP = View->GetOrthoMatrix()*View->GetViewMatrix()*GetModelMatrix();
    glUniformMatrix4fv(MatrixLoc,1,GL_FALSE,&MVP[0][0]);
    glUniform4fv(ColorLoc,1,&(GetColor()[0]));
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER,Buffers[0]);
    glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,NULL);
    glEnableVertexAttribArray(1);
    glBindBuffer(GL_ARRAY_BUFFER,Buffers[1]);
    glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,0,NULL);
    
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_TEXTURE_2D);
    //blahblahblah and then we finally draw using the Size of the Verts array we generated in GenerateBuffers.
    glDrawArrays(GL_QUADS,0,Verts.size());
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);

    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);
    glUseProgram(0);
}
Ejemplo n.º 11
0
 Cube::Cube() {
     // Vertices
     vertexNr = 24;
     vertexData = new Vertex[vertexNr];
 
     // Side 1
     vertexData[0] = {
         glm::vec3(0.5f, 0.5f, 0.5f),
         glm::vec2(1.0f, 0.0f),
         glm::vec3(0.0f, 0.0f, 1.0f),
         glm::vec3(1.0f, 0.0f, 0.0f)
     };
     vertexData[1] = {
         glm::vec3(-0.5f, -0.5f, 0.5f),
         glm::vec2(0.0f, 1.0f),
         glm::vec3(0.0f, 0.0f, 1.0f),
         glm::vec3(1.0f, 0.0f, 0.0f)
     };
     vertexData[2] = {
         glm::vec3(0.5f, -0.5f, 0.5f),
         glm::vec2(1.0f, 1.0f),
         glm::vec3(0.0f, 0.0f, 1.0f),
         glm::vec3(1.0f, 0.0f, 0.0f)
     };
     vertexData[3] = {
         glm::vec3(-0.5f, 0.5f, 0.5f),
         glm::vec2(0.0f, 0.0f),
         glm::vec3(0.0f, 0.0f, 1.0f),
         glm::vec3(1.0f, 0.0f, 0.0f)
     };
 
     // Side 2
     vertexData[4] = {
         glm::vec3(-0.5f, 0.5f, -0.5f),
         glm::vec2(0.0f, 0.0f),
         glm::vec3(-1.0f, 0.0f, 0.0f),
         glm::vec3(0.0f, 0.0f, 1.0f)
     };
     vertexData[5] = {
         glm::vec3(-0.5f, -0.5f, -0.5f),
         glm::vec2(0.0f, 1.0f),
         glm::vec3(-1.0f, 0.0f, 0.0f),
         glm::vec3(0.0f, 0.0f, 1.0f)
     };
     vertexData[6] = {
         glm::vec3(-0.5f, -0.5f, 0.5f),
         glm::vec2(1.0f, 1.0f),
         glm::vec3(-1.0f, 0.0f, 0.0f),
         glm::vec3(0.0f, 0.0f, 1.0f)
     };
     vertexData[7] = {
         glm::vec3(-0.5f, 0.5f, 0.5f),
         glm::vec2(1.0f, 0.0f),
         glm::vec3(-1.0f, 0.0f, 0.0f),
         glm::vec3(0.0f, 0.0f, 1.0f)
     };
 
     // Side 3
     vertexData[8] = {
         glm::vec3(0.5f, 0.5f, -0.5f),
         glm::vec2(1.0f, 0.0f),
         glm::vec3(1.0f, 0.0f, 0.0f),
         glm::vec3(0.0f, 0.0f, -1.0f)
     };
     vertexData[9] = {
         glm::vec3(0.5f, -0.5f, -0.5f),
         glm::vec2(1.0f, 1.0f),
         glm::vec3(1.0f, 0.0f, 0.0f),
         glm::vec3(0.0f, 0.0f, -1.0f)
     };
     vertexData[10] = {
         glm::vec3(0.5f, -0.5f, 0.5f),
         glm::vec2(0.0f, 1.0f),
         glm::vec3(1.0f, 0.0f, 0.0f),
         glm::vec3(0.0f, 0.0f, -1.0f)
     };
     vertexData[11] = {
         glm::vec3(0.5f, 0.5f, 0.5f),
         glm::vec2(0.0f, 0.0f),
         glm::vec3(1.0f, 0.0f, 0.0f),
         glm::vec3(0.0f, 0.0f, -1.0f)
     };
 
     // Side 4
     vertexData[12] = {
         glm::vec3(0.5f, 0.5f, -0.5f),
         glm::vec2(0.0f, 0.0f),
         glm::vec3(0.0f, 0.0f, -1.0f),
         glm::vec3(-1.0f, 0.0f, 0.0f)
     };
     vertexData[13] = {
         glm::vec3(-0.5f, -0.5f, -0.5f),
         glm::vec2(1.0f, 1.0f),
         glm::vec3(0.0f, 0.0f, -1.0f),
         glm::vec3(-1.0f, 0.0f, 0.0f)
     };
     vertexData[14] = {
         glm::vec3(0.5f, -0.5f, -0.5f),
         glm::vec2(0.0f, 1.0f),
         glm::vec3(0.0f, 0.0f, -1.0f),
         glm::vec3(-1.0f, 0.0f, 0.0f)
     };
     vertexData[15] = {
         glm::vec3(-0.5f, 0.5f, -0.5f),
         glm::vec2(1.0f, 0.0f),
         glm::vec3(0.0f, 0.0f, -1.0f),
         glm::vec3(-1.0f, 0.0f, 0.0f)
     };
 
     // Side 5
     vertexData[16] = {
         glm::vec3(-0.5f, -0.5f, 0.5f),
         glm::vec2(0.0f, 0.0f),
         glm::vec3(0.0f, -1.0f, 0.0f),
         glm::vec3(1.0f, 0.0f, 0.0f)
     };
     vertexData[17] = {
         glm::vec3(0.5f, -0.5f, 0.5f),
         glm::vec2(1.0f, 0.0f),
         glm::vec3(0.0f, -1.0f, 0.0f),
         glm::vec3(1.0f, 0.0f, 0.0f)
     };
     vertexData[18] = {
         glm::vec3(0.5f, -0.5f, -0.5f),
         glm::vec2(1.0f, 1.0f),
         glm::vec3(0.0f, -1.0f, 0.0f),
         glm::vec3(1.0f, 0.0f, 0.0f)
     };
     vertexData[19] = {
         glm::vec3(-0.5f, -0.5f, -0.5f),
         glm::vec2(0.0f, 1.0f),
         glm::vec3(0.0f, -1.0f, 0.0f),
         glm::vec3(1.0f, 0.0f, 0.0f)
     };
 
     // Side 6
     vertexData[20] = {
         glm::vec3(-0.5f, 0.5f, 0.5f),
         glm::vec2(0.0f, 0.0f),
         glm::vec3(0.0f, 1.0f, 0.0f),
         glm::vec3(0.0f, 0.0f, -1.0f)
     };
     vertexData[21] = {
         glm::vec3(0.5f, 0.5f, 0.5f),
         glm::vec2(0.0f, 1.0f),
         glm::vec3(0.0f, 1.0f, 0.0f),
         glm::vec3(0.0f, 0.0f, -1.0f)
     };
     vertexData[22] = {
         glm::vec3(0.5f, 0.5f, -0.5f),
         glm::vec2(1.0f, 1.0f),
         glm::vec3(0.0f, 1.0f, 0.0f),
         glm::vec3(0.0f, 0.0f, -1.0f)
     };
     vertexData[23] = {
         glm::vec3(-0.5f, 0.5f, -0.5f),
         glm::vec2(1.0f, 0.0f),
         glm::vec3(0.0f, 1.0f, 0.0f),
         glm::vec3(0.0f, 0.0f, -1.0f)
     };
 
     // Vertexindices
     indexNr = 36;
     indexData = new unsigned int[indexNr];
 
     // Side 1
     indexData[0] = 0;
     indexData[1] = 1;
     indexData[2] = 2;
     indexData[3] = 0;
     indexData[4] = 3;
     indexData[5] = 1;
 
     // Side 2
     indexData[6] = 4;
     indexData[7] = 6;
     indexData[8] = 7;
     indexData[9] = 4;
     indexData[10] = 5;
     indexData[11] = 6;
 
     // Side 3
     indexData[12] = 11;
     indexData[13] = 9;
     indexData[14] = 8;
     indexData[15] = 11;
     indexData[16] = 10;
     indexData[17] = 9;
 
     // Side 4
     indexData[18] = 12;
     indexData[19] = 13;
     indexData[20] = 15;
     indexData[21] = 12;
     indexData[22] = 14;
     indexData[23] = 13;
 
     // Side 5
     indexData[24] = 16;
     indexData[25] = 19;
     indexData[26] = 18;
     indexData[27] = 16;
     indexData[28] = 18;
     indexData[29] = 17;
 
     // Side 6
     indexData[30] = 20;
     indexData[31] = 22;
     indexData[32] = 23;
     indexData[33] = 20;
     indexData[34] = 21;
     indexData[35] = 22;
 
     GenerateBuffers();
     GenerateVertexArray();
 }
Ejemplo n.º 12
0
void NText::DrawText(NCamera* View)
{
    if (Face == NULL || GetColor().w == 0)
    {
        return;
    }
    GenerateBuffers();
    if (Shader == NULL)
    {
        glEnableClientState(GL_VERTEX_ARRAY);
        glBindBuffer(GL_ARRAY_BUFFER,Buffers[0]);
        glVertexPointer(2,GL_FLOAT,0,NULL);

        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        glBindBuffer(GL_ARRAY_BUFFER,Buffers[1]);
        glTexCoordPointer(2,GL_FLOAT,0,NULL);

        glEnable(GL_TEXTURE_2D);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glBindTexture(GL_TEXTURE_2D,Face->GetTexture(Size));

        glMatrixMode(GL_PROJECTION);
        glLoadMatrixf(&View->GetOrthoMatrix()[0][0]);
        glMatrixMode(GL_MODELVIEW);
        glm::mat4 MVP = View->GetViewMatrix()*GetModelMatrix();
        glLoadMatrixf(&MVP[0][0]);

        glColor4fv(&(GetColor()[0]));
        glDrawArrays(GL_QUADS,0,Verts.size());
        glDisable(GL_TEXTURE_2D);
        glDisable(GL_BLEND);

        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
        return;
    }
    glUseProgram(Shader->GetID());
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D,Face->GetTexture(Size));
    glUniform1i(TextureLoc,0);
    glm::mat4 MVP;
    if (!Persp)
    {
        MVP = View->GetOrthoMatrix()*View->GetViewMatrix()*GetModelMatrix();
    } else {
        MVP = View->GetPerspMatrix()*View->GetPerspViewMatrix()*GetModelMatrix();
    }
    glUniformMatrix4fv(MatrixLoc,1,GL_FALSE,&MVP[0][0]);
    glUniform4fv(ColorLoc,1,&(GetColor()[0]));
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER,Buffers[0]);
    glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,NULL);
    glEnableVertexAttribArray(1);
    glBindBuffer(GL_ARRAY_BUFFER,Buffers[1]);
    glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,0,NULL);
    
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_TEXTURE_2D);
    glDrawArrays(GL_QUADS,0,Verts.size());
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);

    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);
    glUseProgram(0);
}
Ejemplo n.º 13
0
void timerCallBack(int value) {

	int incX = 0;
	switch (specialKey) {
	case GLUT_KEY_LEFT:
		incX = -1;
		if (well->CanMove(*cp, incX, 0)) {
			cp->Move(incX, 0, true);
		}
		break;
	case GLUT_KEY_RIGHT:
		incX = 1;
		if (well->CanMove(*cp, incX, 0)) {
			cp->Move(incX, 0, true);
		}
		break;
	}
	specialKey = -1;

	bool isDrop = false;
	switch (key) {
	case SPACEBAR:
		well->Drop(*cp);
		isDrop = true;
		break;
	case ROTATE_LEFT:
		if (well->CanRotateLeft(*cp)) {
			cp->RotateLeft();
			GenerateBuffers(*cp, vbo_cube, ibo_cube_elements);
		}
		break;
	case ROTATE_RIGHT:
		if (well->CanRotateRight(*cp)) {
			cp->RotateRight();
			GenerateBuffers(*cp, vbo_cube, ibo_cube_elements);
		}
		break;
	}
	key = -1;

	if (cp->MustMove()) {
		if (well->CanMove(*cp)) {
			cp->Move(0, 1);
		} else {
			if (isDrop || moveDelay > 10) {
				moveDelay = 0;
				isDrop = false;
				wellEmpty = false;

				well->Add(*cp);

				GenerateBuffers(*well, vbo_fixed, ibo_fixed);

				PickPiece();

				if (well->CanAdd(*cp)) {
					GenerateBuffers(*cp, vbo_cube, ibo_cube_elements);
				} else {
					isGameOver = true;
					glwriter->Write("GAME OVER!", 10, -0.3, 0.0);
				}
			} else {
				moveDelay++;
			}

		}
	} else {
		cp->Increment(false, !isPause, false);
	}

	if (!isGameOver) {
		translate = glm::translate(glm::mat4(1.0f), glm::vec3(cp->getX(), cp->getY(), cp->getZ()));

		glutTimerFunc(100, timerCallBack, 0);
	}

	glutPostRedisplay();
}