Exemplo n.º 1
0
void gles2_init_geometry () {
	// Setup texture coordinates
	float min_u=0;
	float max_u=1.0f;
	float min_v=0;
	float max_v=1.0f;

	uvs[0] = min_u;
	uvs[1] = min_v;
	uvs[2] = max_u;
	uvs[3] = min_v;
	uvs[4] = max_u;
	uvs[5] = max_v;
	uvs[6] = min_u;
	uvs[7] = max_v;
	// 

	glGenBuffers(3, buffers); SHOW_ERROR
	glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); SHOW_ERROR
	glBufferData(GL_ARRAY_BUFFER, kVertexCount * sizeof(GLfloat) * 3, vertices, GL_STATIC_DRAW); SHOW_ERROR
	glBindBuffer(GL_ARRAY_BUFFER, buffers[1]); SHOW_ERROR
	glBufferData(GL_ARRAY_BUFFER, kVertexCount * sizeof(GLfloat) * 2, uvs, GL_STATIC_DRAW); SHOW_ERROR
	glBindBuffer(GL_ARRAY_BUFFER, 0); SHOW_ERROR
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[2]); SHOW_ERROR
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, kIndexCount * sizeof(GL_UNSIGNED_SHORT), indices, GL_STATIC_DRAW); SHOW_ERROR
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); SHOW_ERROR

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f); SHOW_ERROR
	
	glDisable(GL_DEPTH_TEST); SHOW_ERROR
	glDisable(GL_DITHER); SHOW_ERROR
	glDisable(GL_BLEND); SHOW_ERROR

       	SetOrtho(proj, -0.5f, +0.5f, +0.5f, -0.5f, -1.0f, 1.0f, _dispvars->ratio_x, _dispvars->ratio_y);

	// We activate the position and texture coordinate attributes for the vertices
	glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); SHOW_ERROR
	glVertexAttribPointer(shader.a_position, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), NULL); SHOW_ERROR
	glEnableVertexAttribArray(shader.a_position); SHOW_ERROR

	glBindBuffer(GL_ARRAY_BUFFER, buffers[1]); SHOW_ERROR
	glVertexAttribPointer(shader.a_texcoord, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), NULL); SHOW_ERROR
	glEnableVertexAttribArray(shader.a_texcoord); SHOW_ERROR

	// Viewport is configured to the size of the quad on whic we draw the texture.
	glViewport(0, 0, _dispvars->display_width, _dispvars->display_height); SHOW_ERROR

	// We upload the projection matrix
	glUniformMatrix4fv(shader.u_vp_matrix, 1, GL_FALSE, &proj[0][0]); SHOW_ERROR

	// We leave the element array buffer binded so it's binded when we arrive to gles2_draw() on each frame.
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[2]); SHOW_ERROR
}
Exemplo n.º 2
0
void Camera::SetFarZ(float val)
{
    RETURN_IF_EQUAL(mFarZ, val);
    mFarZ = val;
    if (mIsOrtho)
    {
        SetOrtho(mWinSize,mNearZ, mFarZ);
    }
    else
    {
        SetPerspectiveFov(mWinSize,mFovY, mNearZ, mFarZ);
    }
}
Exemplo n.º 3
0
void Camera::ResetDefault(const Size2F& winSize, bool isOrtho /*= false*/)
{
    mWinSize = winSize;
    mIsOrtho = isOrtho;
    float zEye = winSize.Height / 1.1566f;//this magic number will show the picture "pixel-to-pixel" on the screen
    mEyePosition = Point3F(winSize.Width / 2.f, winSize.Height / 2.f, zEye);
    mEyeTarget = Vector3F(winSize.Width / 2.f, winSize.Height / 2.f, 0.f);
    mCameraUp=Vector3F(0.f,1.f,0.f);

    if (mIsOrtho)
    {
        SetOrtho(mWinSize, 0.f, 2048.f);
    }
    else
    {
        mFovY = Math::ToRadian(60.f);
        mNearZ = 0.1f;
        mFarZ = zEye * 2;
        SetPerspectiveFov(mWinSize,mFovY, mNearZ, mFarZ);
    }
    LookAt(mEyePosition,mEyeTarget,mCameraUp);
}
Exemplo n.º 4
0
void Render()
{
	SetOrtho();
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glLoadIdentity();
	glEnable(GL_TEXTURE_2D);

	//sprite.PaintModule(0, 200.0, 200.0, 1);
	//sprite.PaintFrame(0, 300, 10, 1);
	sprite.PaintAnimation(0, 0, 0, 1, true);
#if 0
	glDisable(GL_TEXTURE_2D);
	glTranslatef(64.0f, 64.0f, 0.0f);
	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	glNormal3f(0.0f, 0.0f, 1.0f);

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	float ratio = (float)SCREEN_WIDTH / SCREEN_HEIGHT;
	SetPerspective(45.0f, ratio, 0.1f, 100.0f);
	glLoadIdentity();
	//glDisable(GL_TEXTURE_2D);
	glScalef(0.25f, 0.25f, 0.25f);
	glTranslatef(3.0f, 0.0f, -8.0f);

	glVertexPointer(3, GL_FLOAT, 0, vertices);
	glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	//go through our index array and draw our vertex array
	glDrawElements(GL_TRIANGLE_STRIP, 24, GL_UNSIGNED_BYTE, indices);
	glPopMatrix();
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
#endif	//if0	
	eglSwapBuffers(glesDisplay, glesSurface);
	return;
}