Ejemplo n.º 1
0
static void drawModels(float zScale)
{
    const int translationScale = 9;
    int x, y;

    seedRandom(9);

    //glScalex(1 << 16, 1 << 16, (GLfixed)(zScale * 65536));

    for (y = -5; y <= 5; ++y)
    {
        for (x = -5; x <= 5; ++x)
        {
            float buildingScale;
            GLfixed fixedScale;

            int curShape = randomUInt() % SUPERSHAPE_COUNT;
            buildingScale = sSuperShapeParams[curShape][SUPERSHAPE_PARAMS - 1];
            fixedScale = (GLfixed)(buildingScale * 65536);

#if 0
            glPushMatrix();
            glTranslatex((x * translationScale) * 65536,
                         (y * translationScale) * 65536,
                         0);
            glRotatex((GLfixed)((randomUInt() % 360) << 16), 0, 0, 1 << 16);
            glScalex(fixedScale, fixedScale, fixedScale);

            drawGLObject(sSuperShapeObjects[curShape]);
            glPopMatrix();
#endif
        }
    }

    for (x = -2; x <= 2; ++x)
    {
        const int shipScale100 = translationScale * 500;
        const int offs100 = x * shipScale100 + (sTick % shipScale100);
        float offs = offs100 * 0.01f;
        GLfixed fixedOffs = (GLfixed)(offs * 65536);
#if 0
        glPushMatrix();
        glTranslatex(fixedOffs, -4 * 65536, 2 << 16);
        drawGLObject(sSuperShapeObjects[SUPERSHAPE_COUNT - 1]);
        glPopMatrix();
        glPushMatrix();
        glTranslatex(-4 * 65536, fixedOffs, 4 << 16);
        glRotatex(90 << 16, 0, 0, 1 << 16);
        drawGLObject(sSuperShapeObjects[SUPERSHAPE_COUNT - 1]);
        glPopMatrix();
#endif
    }
}
Ejemplo n.º 2
0
void FGAPIENTRY 
glutStrokeString(void* fontID, const char *string)
{
    int c, i;
    int numchar = (int)strlen((char*) string);
    GLfixed length = 0;
	GLbyte indices[255];
    SFG_StrokeFont* font = fghStrokeByID(fontID);

	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
	glEnableClientState (GL_VERTEX_ARRAY);

	for(i = 0; i < 255; i++)
		indices[i] = i;

    /*
     * Step through the string, drawing each character.
     * A newline will simply translate the next character's insertion
     * point back to the start of the line and down one line.
     */
    for(c = 0; c < numchar; c++)
        if(string[ c ] < font->Quantity)
        {
            if(string[ c ] == '\n')
            {
                glTranslatex(-length, -font->Height, 0);
                length = 0;
            }
            else  /* Not an EOL, draw the bitmap character */
            {
                const SFG_StrokeChar *schar = font->Characters[ string[ c ] ];
                if(schar)
                {
                    const SFG_StrokeStrip *strip = schar->Strips;

                    for(i = 0; i < schar->Number; i++, strip++)
                    {
						glVertexPointer(2, GL_FIXED, 0, strip->Vertices);
						glDrawElements(GL_LINE_STRIP,
							strip->Number,
							GL_UNSIGNED_BYTE,
							indices);
                    }
                    
                    length += schar->Right;
                    glTranslatex(schar->Right, 0, 0);
                }
            }
        }
}
Ejemplo n.º 3
0
void Camera::Update()
{
    Vector3 f = m_center - m_eye;
    //normalize it
    //int test = XTOF(f.z);
    int mag = sqrtx( (int32)(MULX(f.x,f.x) + (int32)MULX(f.y,f.y) + (int32)MULX(f.z,f.z)) );

    int n = DIVX(ITOX(1),mag);

    f.x = MULX(f.x,n);
    f.y = MULX(f.y,n);
    f.z = MULX(f.z,n);

    //update direction
    m_dir = f;


    Vector3 s = f ^ m_up,
            u = s ^ f;

    int matrix[16] = { s.x, u.x, -f.x, 0,
                       s.y, u.y, -f.y, 0,
                       s.z, u.z, -f.z, 0,
                       0,  0,   0,  ITOX(1)
                     };


    glMultMatrixx(matrix);

    glTranslatex(-m_eye.x,-m_eye.y,-m_eye.z);

}
Ejemplo n.º 4
0
  SubCanvas(Canvas &canvas, RasterPoint _offset, PixelSize _size)
#ifdef ENABLE_OPENGL
    :relative(_offset)
#endif
  {
#ifdef ENABLE_OPENGL
    assert(canvas.offset == OpenGL::translate);
#else
    surface = canvas.surface;
#endif
    offset = canvas.offset + _offset;
    size = _size;

#ifdef ENABLE_OPENGL
    if (relative.x != 0 || relative.y != 0) {
      OpenGL::translate += _offset;

      glPushMatrix();
#ifdef HAVE_GLES
      glTranslatex((GLfixed)relative.x << 16, (GLfixed)relative.y << 16, 0);
#else
      glTranslatef(relative.x, relative.y, 0);
#endif
    }
#endif
  }
Ejemplo n.º 5
0
SubCanvas::SubCanvas(Canvas &canvas, RasterPoint _offset, PixelSize _size)
  :relative(_offset)
{
  assert(canvas.offset == OpenGL::translate);
  offset = canvas.offset + _offset;
  
  /* sub canvas bottom right limits can't be outside "parent" canvas. */
  size.cx = std::min<PixelScalar>(_size.cx, canvas.GetSize().cx - _offset.x) ;
  size.cy = std::min<PixelScalar>(_size.cy, canvas.GetSize().cy - _offset.y) ;

  if (relative.x != 0 || relative.y != 0) {
    OpenGL::translate += _offset;

#ifdef USE_GLSL
    glVertexAttrib4f(OpenGL::Attribute::TRANSLATE,
                     OpenGL::translate.x, OpenGL::translate.y, 0, 0);
#else
    glPushMatrix();
#ifdef HAVE_GLES
    glTranslatex((GLfixed)relative.x << 16, (GLfixed)relative.y << 16, 0);
#else
    glTranslatef(relative.x, relative.y, 0);
#endif
#endif /* !USE_GLSL */
  }
  
  if ((relative.x + size.cx < canvas.GetSize().cx) 
          || (relative.y + size.cy < canvas.GetSize().cy)) {

    /* Enable Clipping */
    push_scissor = std::make_unique<GLPushScissor>();
    scissor = std::make_unique<GLCanvasScissor>(*this);
  }
}
Ejemplo n.º 6
0
void
ApplyProjection(const WindowProjection &projection, const GeoPoint &reference)
{
  fixed angle = projection.GetScreenAngle().Degrees();
  fixed scale = projection.GetScale();
  const RasterPoint &screen_origin = projection.GetScreenOrigin();
  const GeoPoint &screen_location = projection.GetGeoLocation();
  const GeoPoint projection_delta = reference - screen_location;

  const fixed scale_r = scale * FAISphere::REARTH;
  const fixed scale_x = scale_r * screen_location.latitude.fastcosine();
  const fixed scale_y = -scale_r;

#ifdef HAVE_GLES
#ifdef FIXED_MATH
  GLfixed fixed_angle = angle.as_glfixed();
#else
  GLfixed fixed_angle = angle * (1<<16);
#endif
  glTranslatex((int)screen_origin.x << 16, (int)screen_origin.y << 16, 0);
  glRotatex(fixed_angle, 0, 0, -(1<<16));
#else
  glTranslatef(screen_origin.x, screen_origin.y, 0.);
  glRotatef((GLfloat)angle, 0., 0., -1.);
#endif

  glScalef(GLfloat(scale_x), GLfloat(scale_y), 1.);
  glTranslatef(GLfloat(projection_delta.longitude.Native()),
               GLfloat(projection_delta.latitude.Native()),
               0.);
}
Ejemplo n.º 7
0
//----------------------------------------------------------------------------
void Render()
{
  static int rotation = 0;
  				  /* Vertex 1    Vertex 2 	 Vertex 3*/                           
  GLshort vertexArray[9] = {-25,-25,0,   25,-25,0,     0,25,0 };
  GLubyte colorArray[12] = {255,0,0,0,   0,255,0,0,    0,0,255,0};
  
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  
  glLoadIdentity();  

  glTranslatex(0, 0, FixedFromInt(-10));
  glRotatex(FixedFromInt(rotation++), 0, ONE,0);  

  //Enable the vertices array  
  glEnableClientState(GL_VERTEX_ARRAY);
  glVertexPointer(3, GL_SHORT, 0, vertexArray);
  //3 = XYZ coordinates, GL_SHORT = data type, 0 = 0 stride bytes
	
  //Enable the vertex color array
  glEnableClientState(GL_COLOR_ARRAY);
  glColorPointer(4,GL_UNSIGNED_BYTE, 0, colorArray);
  //4 = RGBA format, GL_UNSIGNED_BYTE = data type,0=0 stide    bytes

  glDrawArrays(GL_TRIANGLES, 0, 3);
  /*We want draw triangles, 0 = first element(vertice), 3 = number of 
    items (vertices) to draw from the array*/  

  glDisableClientState(GL_VERTEX_ARRAY);
  glDisableClientState(GL_COLOR_ARRAY);
 	
  eglSwapBuffers(glesDisplay, glesSurface);
}
// Draws a char on screen using embedded line font, (x, y) are center of char, not upper-left corner
// TODO: use SDL 1.3 renderer routines? It will not be pixel-aligned then, if the screen is resized
static inline void drawCharWireframe(int idx, Uint16 x, Uint16 y, int rotation, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
    glColor4x(r * 0x100, g * 0x100, b * 0x100, a * 0x100);

    glVertexPointer(2, GL_SHORT, 0, fontGL[idx]);
    glPopMatrix();
    glPushMatrix();
    glTranslatex( x * 0x10000, y * 0x10000, 0 );
    if(rotation != 0)
        glRotatex( rotation, 0, 0, 0x10000 );
    glDrawArrays(GL_LINES, 0, fontGL[idx][FONT_CHAR_LINES_COUNT]);
}
Ejemplo n.º 9
0
void CSimpleCubePbuffer::AppCycle( TInt aFrame )
    {

    glClear( GL_COLOR_BUFFER_BIT );

    // Animate and draw box
    glLoadIdentity();
    glTranslatex( 0 , 0 , -cameraDistance << 16 );
    glRotatex( aFrame << 16, 1 << 16,    0   ,    0    );
    glRotatex( aFrame << 15,    0   , 1 << 16,    0    );
    glRotatex( aFrame << 14,    0   ,    0   , 1 << 16 );
    DrawBox( 15.f, 15.f, 15.f );
    }
Ejemplo n.º 10
0
void FGAPIENTRY 
glutBitmapCharacterPoints(void* fontID, int x, int y, int character)
{
	const GLubyte* face;
	SFG_Font* font = fghFontByID(fontID);

	if(!font)
		return;

    if(!(character >= 1)&&(character < 256))
		return;

    face = font->Characters[ character - 1 ];

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity(); 

	glOrthox(0, _INT2FIXED(fgStructure.Window->State.Width), 0, 
		_INT2FIXED(fgStructure.Window->State.Height), 0, _INT2FIXED(1));
	
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
    glLoadIdentity(); 

	glDisable(GL_DEPTH_TEST);
	
	glTranslatex(_INT2FIXED(x), _INT2FIXED(y), 0);
	__glutBitmapCharacter(font, character);
	glTranslatex(_INT2FIXED(face[0]), 0, 0);

	glEnable(GL_DEPTH_TEST);
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
}
Ejemplo n.º 11
0
void
Canvas::DrawPolyline(const RasterPoint *points, unsigned num_points)
{
#ifdef USE_GLSL
    glm::mat4 matrix = glm::translate(glm::mat4(),glm::vec3(1, 1, 0));
    glUniformMatrix4fv(OpenGL::solid_modelview, 1, GL_FALSE, glm::value_ptr(matrix));
#else
    glPushMatrix();

#ifdef HAVE_GLES
    glTranslatex((GLfixed)1 << 16, (GLfixed)1 << 16, 0);
#else
    glTranslatef(1, 1, 0.);
#endif
#endif
    
#ifdef USE_GLSL
  OpenGL::solid_shader->Use();
#endif

  pen.Bind();
  
  if (pen.GetWidth() <= 2) {
    const ScopeVertexPointer vp(points);
    glDrawArrays(GL_LINE_STRIP, 0, num_points);
  } else {
    const unsigned vertices = LineToTriangles(points, num_points, vertex_buffer,
                                        pen.GetWidth(), false);
    if (vertices > 0) {
      const ScopeVertexPointer vp(vertex_buffer.begin());        
      glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices);
    }
  }

  pen.Unbind();
  
#ifdef USE_GLSL
    glUniformMatrix4fv(OpenGL::solid_modelview, 1, GL_FALSE,
                       glm::value_ptr(glm::mat4()));
#else
    glPopMatrix();
#endif
    
}
Ejemplo n.º 12
0
  CanvasRotateShift(const RasterPoint pos, Angle angle,
                    const int scale = 100) {
#ifdef USE_GLSL
    glm::mat4 matrix = glm::rotate(glm::translate(glm::mat4(),
                                                  glm::vec3(pos.x, pos.y, 0)),
                                   GLfloat(angle.Degrees()),
                                   glm::vec3(0, 0, 1));
    float gl_scale = scale / 100.f;
    if (Layout::ScaleSupported())
      gl_scale *= Layout::scale_1024 / 1024.f;
    matrix = glm::scale(matrix, glm::vec3(gl_scale));
    glUniformMatrix4fv(OpenGL::solid_modelview, 1, GL_FALSE,
                       glm::value_ptr(matrix));
#else
    glPushMatrix();

#ifdef HAVE_GLES
    glTranslatex((GLfixed)pos.x << 16, (GLfixed)pos.y << 16, 0);
    GLfixed fixed_angle = angle.Degrees() * (1<<16);
    glRotatex(fixed_angle, 0, 0, 1<<16);
#else
    glTranslatef(pos.x, pos.y, 0.);
    glRotatef((GLfloat)angle.Degrees(), 0., 0., 1.);
#endif

#ifdef HAVE_GLES
    GLfixed gl_scale = ((GLfixed) scale << 16) / 100;
    if (Layout::ScaleSupported())
      gl_scale = (gl_scale * Layout::scale_1024) >> 10;
    glScalex(gl_scale, gl_scale, (GLfixed)1 << 16);
#else
    float gl_scale = scale / 100.f;
    if (Layout::ScaleSupported())
      gl_scale *= Layout::scale_1024 / 1024.f;
    glScalef(gl_scale, gl_scale, 1.);
#endif
#endif /* USE_GLSL */
  };
Ejemplo n.º 13
0
SubCanvas::SubCanvas(Canvas &canvas, RasterPoint _offset, PixelSize _size)
  :relative(_offset)
{
  assert(canvas.offset == OpenGL::translate);
  offset = canvas.offset + _offset;
  size = _size;

  if (relative.x != 0 || relative.y != 0) {
    OpenGL::translate += _offset;

#ifdef USE_GLSL
    glVertexAttrib4f(OpenGL::Attribute::TRANSLATE,
                     OpenGL::translate.x, OpenGL::translate.y, 0, 0);
#else
    glPushMatrix();
#ifdef HAVE_GLES
    glTranslatex((GLfixed)relative.x << 16, (GLfixed)relative.y << 16, 0);
#else
    glTranslatef(relative.x, relative.y, 0);
#endif
#endif /* !USE_GLSL */
  }
}
Ejemplo n.º 14
0
/*
 * Draw a stroke character
 */
void FGAPIENTRY 
glutStrokeCharacter(void* fontID, int character)
{
    const SFG_StrokeChar *schar;
    const SFG_StrokeStrip *strip;
    int i;
    SFG_StrokeFont* font = fghStrokeByID(fontID);
	GLbyte indices[255];

    if(! (character >= 0) && (character < font->Quantity))
		return;

    schar = font->Characters[ character ];
    if(! schar)
		return;
    strip = schar->Strips;
	
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
	glEnableClientState (GL_VERTEX_ARRAY);

	
	for(i = 0; i < 255; i++)
		indices[i] = i;

    for(i = 0; i < schar->Number; i++, strip++)
    {
		glVertexPointer(2, GL_FIXED, 0, strip->Vertices);
		glDrawElements(GL_LINE_STRIP,
                        strip->Number,
                        GL_UNSIGNED_BYTE,
                        indices);
    }
    glTranslatex((GLfixed)schar->Right, 0, 0);
}
Ejemplo n.º 15
0
void FGAPIENTRY 
glutBitmapStringPoints(void* fontID, int x, int y, const char *string)
{
    SFG_Font* font = fghFontByID(fontID);
	int numchar, xx = 0, yy = 0, nbpoints = 0, i, c;
	GLshort *points;
	GLushort *indices;

	if(!font || !string)
		return;
	if(!string[0])
		return;

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity(); 

	glOrthox(0, _INT2FIXED(fgStructure.Window->State.Width), 0, 
		_INT2FIXED(fgStructure.Window->State.Height), 0, _INT2FIXED(1));

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
    glLoadIdentity(); 

	glDisable(GL_DEPTH_TEST);
	
	glTranslatex(_INT2FIXED(x), _INT2FIXED(y), 0);

	numchar = (int)strlen((char*) string);

	points = (GLshort*)malloc(numchar * 
		font->Height * (*(font->Characters[ 'X' - 1 ])) *
		8 * sizeof(GLshort));

    for(c = 0; c < numchar; c++)
    {
		if(string[c] == '\n')
		{
			yy -= font->Height;
			xx = 0;
		}
		else
		{
			const GLubyte* face = font->Characters[ string[c] - 1 ];
			nbpoints += BitsToIndexedShorts(face+1, face[0], font->Height, points+(nbpoints*2), xx, yy);
			xx += face[0];
		}
	}

	glEnable(GL_ALPHA_TEST);
    glAlphaFuncx(GL_NOTEQUAL, 0);

	indices = (GLushort*)malloc(nbpoints*sizeof(GLushort));
	for(i = 0; i < nbpoints; i++)
		indices[i] = i;

	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
	glEnableClientState (GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_SHORT, 0, points);

	glDrawElements(GL_POINTS,
                        nbpoints,
                        GL_UNSIGNED_SHORT,
                        indices);

	glDisable(GL_ALPHA_TEST);
	free(indices);
	free(points);

	glEnable(GL_DEPTH_TEST);
	
	glPopMatrix();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
}
Ejemplo n.º 16
0
void FGAPIENTRY
glutTrueTypeStringPoints(WCHAR *fontname, int fontsize, int style, int x, int y, const WCHAR *string)
{
	int len, xx = 0, yy = 0, nbpoints = 0, i;
	GLshort *points;
	GLushort *indices;
	HFONT font;
	LOGFONTW	lf;	
	RECT rect;
	static HBITMAP bmp;
	static BYTE *img;
	static HDC hdc = NULL;
	static BITMAPINFO bi;
	SIZE sz;
	static EGLint width, height;

	if(!fontname || !string)
		return;
	if(!string[0])
		return;

	// Initialize static DC and DIB bitmap on the first call
	if(!hdc)
	{		
		// Create a device compatible DC
		hdc = CreateCompatibleDC(GetDC(fgStructure.Window->Window.Handle));	
		
		eglQuerySurface(fgDisplay.eglDisplay, fgStructure.Window->Window.Surface, EGL_WIDTH, &width);
		eglQuerySurface(fgDisplay.eglDisplay, fgStructure.Window->Window.Surface, EGL_HEIGHT, &height);

		// Create a DIB bitmap and attach it to the DC
		ZeroMemory(&bi, sizeof(BITMAPINFO));
		bi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
		bi.bmiHeader.biWidth = width;
		bi.bmiHeader.biHeight = height; 
		bi.bmiHeader.biBitCount = 8;
		bi.bmiHeader.biPlanes = 1;
		bi.bmiHeader.biCompression = BI_RGB;
		
		bmp = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, &img, NULL, 0);
	
		SelectObject(hdc, bmp);
		
		SelectObject(hdc, GetStockObject(BLACK_BRUSH));

		SetBkMode(hdc, TRANSPARENT);
		SetTextColor(hdc, RGB(255, 255, 255));			
	}

	// Erase DC content	with the current black brush
	//Rectangle(hdc, 0, 0, width, height);
	ZeroMemory(img, width * height);

	// Create the font handle and attach it to the DC
	lf.lfCharSet = DEFAULT_CHARSET;
	lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
	lf.lfEscapement = 0;
	wcscpy(lf.lfFaceName, fontname);
	lf.lfHeight = -(fontsize * GetDeviceCaps(GetDC(fgStructure.Window->Window.Handle), LOGPIXELSY) / 72);
	lf.lfItalic = (style & 1) ? TRUE : FALSE;
	lf.lfOrientation = 0;
	lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
	lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
	lf.lfQuality = DEFAULT_QUALITY;
	lf.lfStrikeOut = FALSE;
	lf.lfUnderline = (style & 4) ? TRUE : FALSE;
	lf.lfWidth = 0;
	lf.lfWeight = (style & 2) ? FW_BOLD : FW_NORMAL;
	
	font = CreateFontIndirectW(&lf);

	SelectObject(hdc, font);

	// Draw text in white onto the bitmap
	len = wcslen(string);

	GetTextExtentPointW(hdc, string, len, &sz);

	rect.left = max(0, min(x, width));
	rect.top = max(0, min(y, height));
	rect.right = min(rect.left + sz.cx, width);
	rect.bottom = min(rect.top + sz.cy, height);

	DrawTextW(hdc, string, len, &rect, DT_LEFT | DT_BOTTOM);
	
	// Traverse the bitmap and add all white pixels into a points buffer
	points = (GLshort*)malloc(sz.cx * sz.cy * 2 * sizeof(short));

	for(yy = rect.top; yy < rect.bottom; yy++)
	{
		for(xx = rect.left; xx < rect.right; xx++)
		{
			if(img[xx + (height - yy) * width] != 0)
			{
				points[nbpoints * 2 + 0] = xx - x;
				points[nbpoints * 2 + 1] = (short)(rect.top + sz.cy - (yy - rect.top)) - y;
				nbpoints++;
			}
		}
	}

	// Delete GDI font object
	DeleteObject(font);
	
	// Prepare the index buffer
	indices = (GLushort*)malloc(nbpoints * sizeof(GLushort));
	for(i = 0; i < nbpoints; i++)
		indices[i] = i;

	// Draw the points buffer
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity(); 

	glOrthox(0, _INT2FIXED(width), 
			0, _INT2FIXED(height), 
			0, _INT2FIXED(1));


	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
    glLoadIdentity(); 

	glDisable(GL_DEPTH_TEST);
	
	glTranslatex(_INT2FIXED(x), _INT2FIXED(y), 0);	
	
	glEnable(GL_ALPHA_TEST);
    glAlphaFuncx(GL_NOTEQUAL, 0);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
	glEnableClientState (GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_SHORT, 0, points);

	glDrawElements(GL_POINTS,
                        nbpoints,
                        GL_UNSIGNED_SHORT,
                        indices);
	
	glDisable(GL_ALPHA_TEST);

	glEnable(GL_DEPTH_TEST);

	glPopMatrix();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);

	free(indices);
	free(points);
}
Ejemplo n.º 17
0
void OSystem_Android::updateScreen() {
	//ENTER();

	GLTHREADCHECK;

	if (!JNI::haveSurface())
		return;

	if (!_force_redraw &&
			!_game_texture->dirty() &&
			!_overlay_texture->dirty() &&
			!_mouse_texture->dirty())
		return;

	_force_redraw = false;

	// clear pointer leftovers in dead areas
	// also, HTC's GLES drivers are made of fail and don't preserve the buffer
	// ( http://www.khronos.org/registry/egl/specs/EGLTechNote0001.html )
	if ((_show_overlay || _htc_fail) && !_fullscreen)
		clearScreen(kClear);

	GLCALL(glPushMatrix());

	if (_shake_offset != 0 ||
			(!_focus_rect.isEmpty() &&
			!Common::Rect(_game_texture->width(),
							_game_texture->height()).contains(_focus_rect))) {
		// These are the only cases where _game_texture doesn't
		// cover the entire screen.
		clearScreen(kClear);

		// Move everything up by _shake_offset (game) pixels
		GLCALL(glTranslatex(0, -_shake_offset << 16, 0));
	}

// TODO this doesn't work on those sucky drivers, do it differently
//	if (_show_overlay)
//		GLCALL(glColor4ub(0x9f, 0x9f, 0x9f, 0x9f));

	if (_focus_rect.isEmpty()) {
		_game_texture->drawTextureRect();
	} else {
		GLCALL(glPushMatrix());

		GLCALL(glScalex(xdiv(_egl_surface_width, _focus_rect.width()),
						xdiv(_egl_surface_height, _focus_rect.height()),
						1 << 16));
		GLCALL(glTranslatex(-_focus_rect.left << 16,
							-_focus_rect.top << 16, 0));
		GLCALL(glScalex(xdiv(_game_texture->width(), _egl_surface_width),
						xdiv(_game_texture->height(), _egl_surface_height),
						1 << 16));

		_game_texture->drawTextureRect();

		GLCALL(glPopMatrix());
	}

	int cs = _mouse_targetscale;

	if (_show_overlay) {
// TODO see above
//		GLCALL(glColor4ub(0xff, 0xff, 0xff, 0xff));

		// ugly, but the modern theme sets a wacko factor, only god knows why
		cs = 1;

		GLCALL(_overlay_texture->drawTextureRect());
	}

	if (_show_mouse && !_mouse_texture->isEmpty()) {
		GLCALL(glPushMatrix());

		const Common::Point &mouse = getEventManager()->getMousePos();

		// Scale up ScummVM -> OpenGL (pixel) coordinates
		if (_show_overlay) {
			GLCALL(glScalex(xdiv(_egl_surface_width,
									_overlay_texture->width()),
							xdiv(_egl_surface_height,
									_overlay_texture->height()),
							1 << 16));
		} else {
			const Common::Rect &r = _game_texture->getDrawRect();

			GLCALL(glTranslatex(r.left << 16,
								r.top << 16,
								0));
			GLCALL(glScalex(xdiv(r.width(), _game_texture->width()),
							xdiv(r.height(), _game_texture->height()),
							1 << 16));
		}

		GLCALL(glTranslatex((-_mouse_hotspot.x * cs) << 16,
							(-_mouse_hotspot.y * cs) << 16,
							0));

		// Note the extra half texel to position the mouse in
		// the middle of the x,y square:
		GLCALL(glTranslatex((mouse.x << 16) | 1 << 15,
							(mouse.y << 16) | 1 << 15, 0));

		GLCALL(glScalex(cs << 16, cs << 16, 1 << 16));

		_mouse_texture->drawTextureOrigin();

		GLCALL(glPopMatrix());
	}

	GLCALL(glPopMatrix());

	if (!JNI::swapBuffers())
		LOGW("swapBuffers failed: 0x%x", glGetError());
}
Ejemplo n.º 18
0
void
TopographyFileRenderer::Paint(Canvas &canvas,
                              const WindowProjection &projection)
{
  if (file.IsEmpty())
    return;

  fixed map_scale = projection.GetMapScale();
  if (!file.IsVisible(map_scale))
    return;

  UpdateVisibleShapes(projection);

  if (visible_shapes.empty())
    return;

  // TODO code: only draw inside screen!
  // this will save time with rendering pixmaps especially
  // we already do an outer visibility test, but may need a test
  // in screen coords

#ifdef ENABLE_OPENGL
  pen.Set();
  brush.Set();
#else
  shape_renderer.Configure(&pen, &brush);
#endif

  // get drawing info

#ifdef ENABLE_OPENGL
  const unsigned level = file.GetThinningLevel(map_scale);
  const unsigned min_distance = file.GetMinimumPointDistance(level)
    / Layout::Scale(1);

#ifndef HAVE_GLES
  float opengl_matrix[16];
  glGetFloatv(GL_MODELVIEW_MATRIX, opengl_matrix);
#endif

  glPushMatrix();
  fixed angle = projection.GetScreenAngle().Degrees();
  fixed scale = projection.GetScale();
  const RasterPoint &screen_origin = projection.GetScreenOrigin();
#ifdef HAVE_GLES
#ifdef FIXED_MATH
  GLfixed fixed_angle = angle.as_glfixed();
  GLfixed fixed_scale = scale.as_glfixed_scale();
#else
  GLfixed fixed_angle = angle * (1<<16);
  GLfixed fixed_scale = scale * (1LL<<32);
#endif
  glTranslatex((int)screen_origin.x << 16, (int)screen_origin.y << 16, 0);
  glRotatex(fixed_angle, 0, 0, -(1<<16));
  glScalex(fixed_scale, fixed_scale, 1<<16);
#else
  glTranslatef(screen_origin.x, screen_origin.y, 0.);
  glRotatef((GLfloat)angle, 0., 0., -1.);
  glScalef((GLfloat)scale, (GLfloat)scale, 1.);
#endif
#else // !ENABLE_OPENGL
  const GeoClip clip(projection.GetScreenBounds().Scale(fixed(1.1)));
  AllocatedArray<GeoPoint> geo_points;

  int iskip = file.GetSkipSteps(map_scale);
#endif

  for (auto it = visible_shapes.begin(), end = visible_shapes.end();
       it != end; ++it) {
    const XShape &shape = **it;

    if (!projection.GetScreenBounds().Overlaps(shape.get_bounds()))
      continue;

#ifdef ENABLE_OPENGL
    const ShapePoint *points = shape.get_points();

    const ShapePoint translation =
      shape.shape_translation(projection.GetGeoLocation());
    glPushMatrix();
#ifdef HAVE_GLES
    glTranslatex(translation.x, translation.y, 0);
#else
    glTranslatef(translation.x, translation.y, 0.);
#endif
#else // !ENABLE_OPENGL
    const unsigned short *lines = shape.get_lines();
    const unsigned short *end_lines = lines + shape.get_number_of_lines();
    const GeoPoint *points = shape.get_points();
#endif

    switch (shape.get_type()) {
    case MS_SHAPE_NULL:
      break;

    case MS_SHAPE_POINT:
#ifdef ENABLE_OPENGL
#ifdef HAVE_GLES
      PaintPoint(canvas, projection, shape, NULL);
#else
      PaintPoint(canvas, projection, shape, opengl_matrix);
#endif
#else // !ENABLE_OPENGL
      PaintPoint(canvas, projection, lines, end_lines, points);
#endif
      break;

    case MS_SHAPE_LINE:
      {
#ifdef ENABLE_OPENGL
#ifdef HAVE_GLES
        glVertexPointer(2, GL_FIXED, 0, &points[0].x);
#else
        glVertexPointer(2, GL_INT, 0, &points[0].x);
#endif

        const GLushort *indices, *count;
        if (level == 0 ||
            (indices = shape.get_indices(level, min_distance, count)) == NULL) {
          count = shape.get_lines();
          const GLushort *end_count = count + shape.get_number_of_lines();
          for (int offset = 0; count < end_count; offset += *count++)
            glDrawArrays(GL_LINE_STRIP, offset, *count);
        } else {
          const GLushort *end_count = count + shape.get_number_of_lines();
          for (; count < end_count; indices += *count++)
            glDrawElements(GL_LINE_STRIP, *count, GL_UNSIGNED_SHORT, indices);
        }
#else // !ENABLE_OPENGL
      for (; lines < end_lines; ++lines) {
        unsigned msize = *lines;
        shape_renderer.Begin(msize);

        const GeoPoint *end = points + msize - 1;
        for (; points < end; ++points)
          shape_renderer.AddPointIfDistant(projection.GeoToScreen(*points));

        // make sure we always draw the last point
        shape_renderer.AddPoint(projection.GeoToScreen(*points));

        shape_renderer.FinishPolyline(canvas);
      }
#endif
      }
      break;

    case MS_SHAPE_POLYGON:
#ifdef ENABLE_OPENGL
      {
        const GLushort *index_count;
        const GLushort *triangles = shape.get_indices(level, min_distance,
                                                        index_count);

#ifdef HAVE_GLES
        glVertexPointer(2, GL_FIXED, 0, &points[0].x);
#else
        glVertexPointer(2, GL_INT, 0, &points[0].x);
#endif
        glDrawElements(GL_TRIANGLE_STRIP, *index_count, GL_UNSIGNED_SHORT,
                       triangles);
      }
#else // !ENABLE_OPENGL
      for (; lines < end_lines; ++lines) {
        unsigned msize = *lines / iskip;

        /* copy all polygon points into the geo_points array and clip
           them, to avoid integer overflows (as RasterPoint may store
           only 16 bit integers on some platforms) */

        geo_points.GrowDiscard(msize * 3);

        for (unsigned i = 0; i < msize; ++i)
          geo_points[i] = points[i * iskip];

        msize = clip.ClipPolygon(geo_points.begin(),
                                 geo_points.begin(), msize);
        if (msize < 3)
          continue;

        shape_renderer.Begin(msize);

        for (unsigned i = 0; i < msize; ++i) {
          GeoPoint g = geo_points[i];
          shape_renderer.AddPointIfDistant(projection.GeoToScreen(g));
        }

        shape_renderer.FinishPolygon(canvas);
      }
#endif
      break;
    }
#ifdef ENABLE_OPENGL
    glPopMatrix();
#endif
  }
#ifdef ENABLE_OPENGL
  glPopMatrix();
#else
  shape_renderer.Commit();
#endif
}
Ejemplo n.º 19
0
static void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
	              GLfloat centerx, GLfloat centery, GLfloat centerz,
	              GLfloat upx, GLfloat upy, GLfloat upz)
{
    GLfloat m[16];
    GLfloat x[3], y[3], z[3];
    GLfloat mag;

    z[0] = eyex - centerx;
    z[1] = eyey - centery;
    z[2] = eyez - centerz;
    mag = (float)sqrt(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]);
    if (mag) {		
        z[0] /= mag;
        z[1] /= mag;
        z[2] /= mag;
    }


    y[0] = upx;
    y[1] = upy;
    y[2] = upz;


    x[0] = y[1] * z[2] - y[2] * z[1];
    x[1] = -y[0] * z[2] + y[2] * z[0];
    x[2] = y[0] * z[1] - y[1] * z[0];


    y[0] = z[1] * x[2] - z[2] * x[1];
    y[1] = -z[0] * x[2] + z[2] * x[0];
    y[2] = z[0] * x[1] - z[1] * x[0];



    mag = (float)sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
    if (mag) {
        x[0] /= mag;
        x[1] /= mag;
        x[2] /= mag;
    }

    mag = (float)sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]);
    if (mag) {
        y[0] /= mag;
        y[1] /= mag;
        y[2] /= mag;
    }

#define M(row,col)  m[col*4+row]
    M(0, 0) = x[0];
    M(0, 1) = x[1];
    M(0, 2) = x[2];
    M(0, 3) = 0.0;
    M(1, 0) = y[0];
    M(1, 1) = y[1];
    M(1, 2) = y[2];
    M(1, 3) = 0.0;
    M(2, 0) = z[0];
    M(2, 1) = z[1];
    M(2, 2) = z[2];
    M(2, 3) = 0.0;
    M(3, 0) = 0.0;
    M(3, 1) = 0.0;
    M(3, 2) = 0.0;
    M(3, 3) = 1.0;
#undef M
    {
        int a;
        GLfixed fixedM[16];
        for (a = 0; a < 16; ++a)
            fixedM[a] = (GLfixed)(m[a] * 65536);
        glMultMatrixx(fixedM);
    }


    glTranslatex((GLfixed)(-eyex * 65536),
                 (GLfixed)(-eyey * 65536),
                 (GLfixed)(-eyez * 65536));
}
void glTranslatexLogged(GLfixed x, GLfixed y, GLfixed z) {
	printf("glTranslatex(%i, %i, %i)\n", x, y, z);
	glTranslatex(x, y, z);
}
Ejemplo n.º 21
0
void CLT3DEngine::Render()
	{
	glClear(GL_COLOR_BUFFER_BIT);

	glLoadIdentity();
	glTranslatex(0, 0, iCameraDistance << 16);
	glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); // 清除屏幕和深度缓存
	//	glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT
	//		| GL_LIGHTING_BIT | GL_TRANSFORM_BIT | GL_TEXTURE_BIT);

	glDisable(GL_DEPTH_TEST);
	glDisable(GL_LIGHTING);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);

	glEnable(GL_TEXTURE_2D);

	//以上代码使黑色透明

	//glLoadIdentity(); // 重置当前的模型观察矩阵
	/***********************************新添的代码***********************************************************************************/
	for (loop = 0; loop < MAX_PARTICLES; loop++) // 循环所有的粒子
		{
		if (particle[loop].active) // 如果粒子为激活的
			{
			float x = particle[loop].x; // 返回X轴的位置
			float y = particle[loop].y; // 返回Y轴的位置
			float z = particle[loop].z + zoom; // 返回Z轴的位置
			// 设置粒子颜色

			glPushMatrix();

			glColor4f(particle[loop].r, particle[loop].g, particle[loop].b,
					particle[loop].life);

			glTranslatef(x, y, z);
			glBindTexture(GL_TEXTURE_2D, iOpenGLES.iID);
			glDrawElements(GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, triangles);

			glPopMatrix();

			//			glBegin(GL_TRIANGLE_STRIP);				// 绘制三角形带
			//				glTexCoord2d(1,1); glVertex3f(x+0.5f,y+0.5f,z); 
			//				glTexCoord2d(0,1); glVertex3f(x-0.5f,y+0.5f,z); 
			//				glTexCoord2d(1,0); glVertex3f(x+0.5f,y-0.5f,z); 
			//				glTexCoord2d(0,0); glVertex3f(x-0.5f,y-0.5f,z); 
			//			glEnd();

			particle[loop].x += particle[loop].xi / (slowdown * 1000); // 更新X坐标的位置
			particle[loop].y += particle[loop].yi / (slowdown * 1000); // 更新Y坐标的位置
			particle[loop].z += particle[loop].zi / (slowdown * 1000); // 更新Z坐标的位置
			particle[loop].xi += particle[loop].xg; // 更新X轴方向速度大小
			particle[loop].yi += particle[loop].yg; // 更新Y轴方向速度大小
			particle[loop].zi += particle[loop].zg; // 更新Z轴方向速度大小
			particle[loop].life -= particle[loop].fade; // 减少粒子的生命值
			if (particle[loop].life < 0.0f) // 如果粒子生命值小于0
				{
				particle[loop].life = 1.0f; // 产生一个新的粒子
				particle[loop].fade = float(Math::Random() % 100) / 1000.0f
						+ 0.003f; // 随机生成衰减速率
				particle[loop].x = 0.0f; // 新粒子出现在屏幕的中央
				particle[loop].y = 0.0f;
				particle[loop].z = 0.0f;
				
//				particle[loop].xi = xspeed + float((Math::Random() % 60)
//						- 32.0f); // 随机生成粒子速度
//				particle[loop].yi = yspeed + float((Math::Random() % 60)
//						- 30.0f);
//				particle[loop].zi = float((Math::Random() % 60) - 30.0f);
				
				particle[loop].xi=float((Math::Random()%50)-25.0f)*10.0f;		// 随机生成X轴方向速度
				particle[loop].yi=float((Math::Random()%50)-25.0f)*10.0f;		// 随机生成Y轴方向速度
				particle[loop].zi=float((Math::Random()%50)-25.0f)*10.0f;		// 随机生成Z轴方向速度
				particle[loop].xg=float(Math::Random()%50)/1000.0f;									// 设置X轴方向加速度为0
				particle[loop].yg=float(Math::Random()%50)/1000.0f;								// 设置Y轴方向加速度为-0.8
				particle[loop].zg=float(Math::Random()%50)/1000.0f;									// 设置Z轴方向加速度为0
						
				
				particle[loop].r = colors[col][0]; // 设置粒子颜色
				particle[loop].g = colors[col][1];
				particle[loop].b = colors[col][2];
				}
			}
		}	
	col++;
	if (col > 11)
		col = 0;

	eglSwapBuffers(iEglDisplay, iEglSurface);

	}
Ejemplo n.º 22
0
void
Canvas::DrawCircle(int x, int y, unsigned radius)
{
#ifdef USE_GLSL
  OpenGL::solid_shader->Use();
#endif

  if (IsPenOverBrush() && pen.GetWidth() > 2) {
    ScopeVertexPointer vp;
    GLDonutVertices vertices(x, y,
                             radius - pen.GetWidth() / 2,
                             radius + pen.GetWidth() / 2);
    if (!brush.IsHollow()) {
      vertices.BindInnerCircle(vp);
      brush.Set();
      glDrawArrays(GL_TRIANGLE_FAN, 0, vertices.CIRCLE_SIZE);
    }
    vertices.Bind(vp);
    pen.Bind();
    glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.SIZE);
    pen.Unbind();
  } else {
    GLFallbackArrayBuffer &buffer = radius < 16
      ? *OpenGL::small_circle_buffer
      : *OpenGL::circle_buffer;
    const unsigned n = radius < 16
      ? OpenGL::SMALL_CIRCLE_SIZE
      : OpenGL::CIRCLE_SIZE;

    const FloatPoint *const points = (const FloatPoint *)buffer.BeginRead();
    const ScopeVertexPointer vp(points);

#ifdef USE_GLSL
    glm::mat4 matrix2 = glm::scale(glm::translate(glm::mat4(),
                                                  glm::vec3(x, y, 0)),
                                   glm::vec3(GLfloat(radius), GLfloat(radius),
                                             1.));
    glUniformMatrix4fv(OpenGL::solid_modelview, 1, GL_FALSE,
                       glm::value_ptr(matrix2));
#else
    glPushMatrix();

#ifdef HAVE_GLES
    glTranslatex((GLfixed)x << 16, (GLfixed)y << 16, 0);
    glScalex((GLfixed)radius << 16, (GLfixed)radius << 16, (GLfixed)1 << 16);
#else
    glTranslatef(x, y, 0.);
    glScalef(radius, radius, 1.);
#endif
#endif

    if (!brush.IsHollow()) {
      brush.Set();
      glDrawArrays(GL_TRIANGLE_FAN, 0, n);
    }

    if (IsPenOverBrush()) {
      pen.Bind();
      glDrawArrays(GL_LINE_LOOP, 0, n);
      pen.Unbind();
    }

#ifdef USE_GLSL
    glUniformMatrix4fv(OpenGL::solid_modelview, 1, GL_FALSE,
                       glm::value_ptr(glm::mat4()));
#else
    glPopMatrix();
#endif

    buffer.EndRead();
  }
}
Ejemplo n.º 23
0
void CLT3DEngine::DrawTangram()
	{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
		
	GLint width,height;
	width = iScreenWidth  >> 1;
	height = iScreenHeight >> 1;
	glOrthof((float)-width, (float) width, (float)-height, (float) height, -1, 1); // set the same size as viewport
		

	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();
	glScalef(1.0f / 255.0f, 1.0f / 255.0f, 1.0f);
	glTranslatef(128.0f, 128.0f, 0.0f);
		
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
	    
	glVertexPointer(2, GL_BYTE, 0, verticesTangram);
	glTexCoordPointer(2, GL_BYTE, 0, nokTexCoordsTangram);

	/* Animate and draw box */
	glColor4f(1.0f,1.0f,1.0f,1.0f);
	if (ETrue)
		{
		glPushMatrix();
//		glTranslatex(0, 0, iCameraDistance << 16);
		
		glRotatex(iRotate[0] << 16, 0, 0, 1 << 16);
		
		glScalex(25 << 16, 25<<16 ,1 << 16);
		
		glTranslatex(iTranslate[0][0] << 16, 0, 0);
		glTranslatex(0, iTranslate[0][1] << 16, 0);		
		
//		glTranslatex(0, 2<<16, 0);
//		glRotatex(iRotate[0] << 16, 0, 0, 1 << 16);
//		glTranslatex(0, -2<<16, 0);
		
		//		glRotatex(0,iRotate<<16,0,0);
		//		glRotatex(0,0,iRotate<<16,0);

		glBindTexture(  GL_TEXTURE_2D, iOpenGLES.iID );
		glDrawElements(GL_TRIANGLES, 1 * 3, GL_UNSIGNED_BYTE, STTtriangleBig1);
		
		glPopMatrix();
		}

	if (ETrue)
		{
		glPushMatrix();
//		glTranslatex(0, 0, iCameraDistance << 16);
		glScalex(25 << 16, 25<<16 ,1 << 16);
				
		glTranslatex(iTranslate[1][0] << 16, 0, 0);
		glTranslatex(0, iTranslate[1][1] << 16, 0);
		
		glTranslatex(-2<<16, 0, 0);
		glRotatex(iRotate[1] << 16, 0, 0, 1 << 16);
		glTranslatex(2<<16, 0, 0);
		
		glBindTexture(  GL_TEXTURE_2D, iOpenGLES.iID );
		glDrawElements(GL_TRIANGLES, 1 * 3, GL_UNSIGNED_BYTE, STTtriangleBig2);
		
		glPopMatrix();
		}

	if (ETrue)
		{
		glPushMatrix();
//		glTranslatex(0, 0, iCameraDistance << 16);

		glScalex(25 << 16, 25<<16 ,1 << 16);
		
		glTranslatex(iTranslate[2][0] << 16, 0, 0);
		glTranslatex(0, iTranslate[2][1] << 16, 0);
		
		glTranslatex(1<<16, 0, 0);
		glRotatex(iRotate[2] << 16, 0, 0, 1 << 16);
		glTranslatex(-1<<16, 0, 0);
		
		glBindTexture(  GL_TEXTURE_2D, iOpenGLES.iID );
		glDrawElements(GL_TRIANGLES, 1 * 3, GL_UNSIGNED_BYTE, STTtriangleSmall1);
		
		glPopMatrix();
		}

	if (ETrue)
		{
		glPushMatrix();
//		glTranslatex(0, 0, iCameraDistance << 16);

		glScalex(25 << 16, 25<<16 ,1 << 16);
		
		glTranslatex(iTranslate[3][0] << 16, 0, 0);
		glTranslatex(0, iTranslate[3][1] << 16, 0);
		
		glTranslatex(-2<<16, -3<<16, 0);
		glRotatex(iRotate[3] << 16, 0, 0, 1 << 16);
		glTranslatex(2<<16, 3<<16, 0);
		
		glBindTexture(  GL_TEXTURE_2D, iOpenGLES.iID );
		glDrawElements(GL_TRIANGLES, 1 * 3, GL_UNSIGNED_BYTE, STTtriangleSmall2);
		
		glPopMatrix();
		}

	if (ETrue)
		{
		glPushMatrix();
//		glTranslatex(0, 0, iCameraDistance << 16);

		glScalex(25 << 16, 25<<16 ,1 << 16);
		
		glTranslatex(iTranslate[4][0] << 16, 0, 0);
		glTranslatex(0, iTranslate[4][1] << 16, 0);
		
		glTranslatex(3<<16, -3<<16, 0);
		glRotatex(iRotate[4] << 16, 0, 0, 1 << 16);
		glTranslatex(-3<<16, 3<<16, 0);
		
		glBindTexture(  GL_TEXTURE_2D, iOpenGLES.iID );
		glDrawElements(GL_TRIANGLES, 1 * 3, GL_UNSIGNED_BYTE, STTtriangleMid);
		
		glPopMatrix();
		}

	if (ETrue)
		{
		glPushMatrix();
//		glTranslatex(0, 0, iCameraDistance << 16);

		glScalex(25 << 16, 25<<16 ,1 << 16);
		
		glTranslatex(iTranslate[5][0] << 16, 0, 0);
		glTranslatex(0, iTranslate[5][1] << 16, 0);
		
		glTranslatex(0, -2<<16, 0);
		glRotatex(iRotate[5] << 16, 0, 0, 1 << 16);
		glTranslatex(0, 2<<16, 0);
		
		glBindTexture(  GL_TEXTURE_2D, iOpenGLES.iID );
		glDrawElements(GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, STSquare);
		
		glPopMatrix();
		}

	if (ETrue)
		{
		glPushMatrix();
//		glTranslatex(0, 0, iCameraDistance << 16);

		glScalex(25 << 16, 25<<16 ,1 << 16);
		
		glTranslatex(iTranslate[6][0] << 16, 0, 0);
		glTranslatex(0, iTranslate[6][1] << 16, 0);
		
		glTranslatex(3<<16, 1<<16, 0);
		glRotatex(iRotate[6] << 16, 0, 0, 1 << 16);
		glTranslatex(-3<<16, -1<<16, 0);
		
		glBindTexture(  GL_TEXTURE_2D, iOpenGLES.iID );
		glDrawElements(GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, STRect);
		
		glPopMatrix();
		}
	
	}
Ejemplo n.º 24
0
/* Following gluLookAt implementation is adapted from the
 * Mesa 3D Graphics library. http://www.mesa3d.org
 */
static void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
	              GLfloat centerx, GLfloat centery, GLfloat centerz,
	              GLfloat upx, GLfloat upy, GLfloat upz)
{
    GLfloat m[16];
    GLfloat x[3], y[3], z[3];
    GLfloat mag;

    /* Make rotation matrix */

    /* Z vector */
    z[0] = eyex - centerx;
    z[1] = eyey - centery;
    z[2] = eyez - centerz;
    mag = (float)sqrt(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]);
    if (mag) {			/* mpichler, 19950515 */
        z[0] /= mag;
        z[1] /= mag;
        z[2] /= mag;
    }

    /* Y vector */
    y[0] = upx;
    y[1] = upy;
    y[2] = upz;

    /* X vector = Y cross Z */
    x[0] = y[1] * z[2] - y[2] * z[1];
    x[1] = -y[0] * z[2] + y[2] * z[0];
    x[2] = y[0] * z[1] - y[1] * z[0];

    /* Recompute Y = Z cross X */
    y[0] = z[1] * x[2] - z[2] * x[1];
    y[1] = -z[0] * x[2] + z[2] * x[0];
    y[2] = z[0] * x[1] - z[1] * x[0];

    /* mpichler, 19950515 */
    /* cross product gives area of parallelogram, which is < 1.0 for
     * non-perpendicular unit-length vectors; so normalize x, y here
     */

    mag = (float)sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
    if (mag) {
        x[0] /= mag;
        x[1] /= mag;
        x[2] /= mag;
    }

    mag = (float)sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]);
    if (mag) {
        y[0] /= mag;
        y[1] /= mag;
        y[2] /= mag;
    }

#define M(row,col)  m[(col)*4+(row)]
    M(0, 0) = x[0];
    M(0, 1) = x[1];
    M(0, 2) = x[2];
    M(0, 3) = 0.0;
    M(1, 0) = y[0];
    M(1, 1) = y[1];
    M(1, 2) = y[2];
    M(1, 3) = 0.0;
    M(2, 0) = z[0];
    M(2, 1) = z[1];
    M(2, 2) = z[2];
    M(2, 3) = 0.0;
    M(3, 0) = 0.0;
    M(3, 1) = 0.0;
    M(3, 2) = 0.0;
    M(3, 3) = 1.0;
#undef M
    {
        int a;
        GLfixed fixedM[16];
        for (a = 0; a < 16; ++a)
            fixedM[a] = (GLfixed)(m[a] * 65536);
        glMultMatrixx(fixedM);
    }

    /* Translate Eye to Origin */
    glTranslatex((GLfixed)(-eyex * 65536),
                 (GLfixed)(-eyey * 65536),
                 (GLfixed)(-eyez * 65536));
}
Ejemplo n.º 25
0
void CLT3DEngine::DrawParticles()
	{
	// Recalculate the view frustrum
//	glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); // 清除屏幕和深度缓存
//	
//	glMatrixMode(GL_PROJECTION);
//	glLoadIdentity();
//	GLfloat aspectRatio = (GLfloat) (iScreenWidth) / (GLfloat) (iScreenHeight);
//	glFrustumf(FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio,
//			FRUSTUM_BOTTOM, FRUSTUM_TOP,
//			FRUSTUM_NEAR, FRUSTUM_FAR );
//
//	// Enable back face culling.
//
//	glMatrixMode(GL_TEXTURE);
//	glLoadIdentity();
//	glScalef(1.0f / 255.0f, 1.0f / 255.0f, 1.0f);
//	glTranslatef(128.0f, 128.0f, 0.0f);
//
//	glMatrixMode(GL_MODELVIEW);
//	glLoadIdentity();
//	
//	glVertexPointer(3, GL_BYTE, 0, vertices);
//	glTexCoordPointer(2, GL_BYTE, 0, nokTexCoords);
//	
//	glEnable(GL_BLEND);
//	glBlendFunc(GL_SRC_ALPHA,GL_ONE);

//		glEnable(GL_TEXTURE_2D);
		
	// Set array pointers.
	
	//		glEnable(GL_TEXTURE_2D);

			//以上代码使黑色透明
	
	glClear(GL_COLOR_BUFFER_BIT);

	glLoadIdentity();
	glTranslatex(0, 0, iCameraDistance << 16);
	
	glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); // 清除屏幕和深度缓存
	//	glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT
	//		| GL_LIGHTING_BIT | GL_TRANSFORM_BIT | GL_TEXTURE_BIT);

	glDisable(GL_DEPTH_TEST);
	glDisable(GL_LIGHTING);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);

	glEnable(GL_TEXTURE_2D);

			//glLoadIdentity(); // 重置当前的模型观察矩阵
//	glLoadIdentity();
//	glTranslatex(0, 0, iCameraDistance << 16);
			/***********************************新添的代码***********************************************************************************/
			for (loop = 0; loop < MAX_PARTICLES; loop++) // 循环所有的粒子
				{
				if (particle[loop].active) // 如果粒子为激活的
					{
					float x = particle[loop].x; // 返回X轴的位置
					float y = particle[loop].y; // 返回Y轴的位置
					float z = particle[loop].z + zoom; // 返回Z轴的位置
					// 设置粒子颜色

					glPushMatrix();

					glColor4f(particle[loop].r, particle[loop].g, particle[loop].b,
							particle[loop].life);

					glTranslatef(x, y, z);
					glScalef(10.0f,10.0f,1.0f);
					glBindTexture(GL_TEXTURE_2D, iTextureParticle.iID);
					glDrawElements(GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, triangles);

					glPopMatrix();

					//			glBegin(GL_TRIANGLE_STRIP);				// 绘制三角形带
					//				glTexCoord2d(1,1); glVertex3f(x+0.5f,y+0.5f,z); 
					//				glTexCoord2d(0,1); glVertex3f(x-0.5f,y+0.5f,z); 
					//				glTexCoord2d(1,0); glVertex3f(x+0.5f,y-0.5f,z); 
					//				glTexCoord2d(0,0); glVertex3f(x-0.5f,y-0.5f,z); 
					//			glEnd();

					particle[loop].x += particle[loop].xi / (slowdown * 1000); // 更新X坐标的位置
					particle[loop].y += particle[loop].yi / (slowdown * 1000); // 更新Y坐标的位置
					particle[loop].z += particle[loop].zi / (slowdown * 1000); // 更新Z坐标的位置
					particle[loop].xi += particle[loop].xg; // 更新X轴方向速度大小
					particle[loop].yi += particle[loop].yg; // 更新Y轴方向速度大小
					particle[loop].zi += particle[loop].zg; // 更新Z轴方向速度大小
					particle[loop].life -= particle[loop].fade; // 减少粒子的生命值
					if (particle[loop].life < 0.0f) // 如果粒子生命值小于0
						{
						particle[loop].life = 1.0f; // 产生一个新的粒子
						particle[loop].fade = float(Math::Random() % 100) / 1000.0f
								+ 0.003f; // 随机生成衰减速率
						particle[loop].x = 0.0f; // 新粒子出现在屏幕的中央
						particle[loop].y = 0.0f;
						particle[loop].z = 0.0f;
						
		//				particle[loop].xi = xspeed + float((Math::Random() % 60)
		//						- 32.0f); // 随机生成粒子速度
		//				particle[loop].yi = yspeed + float((Math::Random() % 60)
		//						- 30.0f);
		//				particle[loop].zi = float((Math::Random() % 60) - 30.0f);
						
						particle[loop].xi=float((Math::Random()%50)-25.0f)*10.0f;		// 随机生成X轴方向速度
						particle[loop].yi=float((Math::Random()%50)-25.0f)*10.0f;		// 随机生成Y轴方向速度
						particle[loop].zi=float((Math::Random()%50)-25.0f)*10.0f;		// 随机生成Z轴方向速度
						particle[loop].xg=float(Math::Random()%50)/1000.0f;									// 设置X轴方向加速度为0
						particle[loop].yg=float(Math::Random()%50)/1000.0f;								// 设置Y轴方向加速度为-0.8
						particle[loop].zg=float(Math::Random()%50)/1000.0f;									// 设置Z轴方向加速度为0
								
						
						particle[loop].r = colors[col][0]; // 设置粒子颜色
						particle[loop].g = colors[col][1];
						particle[loop].b = colors[col][2];
						}
					}
				}	
			
			col++;
			if (col > 11)
				col = 0;
	}
Ejemplo n.º 26
0
void OSystem_Android::updateScreen() {
	//ENTER();

	GLTHREADCHECK;

	if (!JNI::haveSurface())
		return;

		if (_game_pbuf) {
			int pitch = _game_texture->width() * _game_texture->getPixelFormat().bytesPerPixel;
			_game_texture->updateBuffer(0, 0, _game_texture->width(), _game_texture->height(),
					_game_pbuf.getRawBuffer(), pitch);
		}

		if (!_force_redraw &&
				!_game_texture->dirty() &&
				!_overlay_texture->dirty() &&
				!_mouse_texture->dirty())
			return;

		_force_redraw = false;

		if (_frame_buffer) {
			_frame_buffer->detach();
			glViewport(0,0, _egl_surface_width, _egl_surface_height);
		}

		// clear pointer leftovers in dead areas
		clearScreen(kClear);

	// TODO this doesnt work on those sucky drivers, do it differently
	//	if (_show_overlay)
	//		GLCALL(glColor4ub(0x9f, 0x9f, 0x9f, 0x9f));

		if (true || _focus_rect.isEmpty()) {
			_game_texture->drawTextureRect();
			drawVirtControls();
		} else {
// TODO what is this and do we have engines using it?
#if 0
			GLCALL(glPushMatrix());

			GLCALL(glScalex(xdiv(_egl_surface_width, _focus_rect.width()),
							xdiv(_egl_surface_height, _focus_rect.height()),
							1 << 16));
			GLCALL(glTranslatex(-_focus_rect.left << 16,
								-_focus_rect.top << 16, 0));
			GLCALL(glScalex(xdiv(_game_texture->width(), _egl_surface_width),
							xdiv(_game_texture->height(), _egl_surface_height),
							1 << 16));

			_game_texture->drawTextureRect();

			GLCALL(glPopMatrix());
#endif
		}

		int cs = _mouse_targetscale;

		if (_show_overlay) {
	// TODO see above
	//		GLCALL(glColor4ub(0xff, 0xff, 0xff, 0xff));

			// ugly, but the modern theme sets a wacko factor, only god knows why
			cs = 1;

			GLCALL(_overlay_texture->drawTextureRect());
		}

		if (_show_mouse && !_mouse_texture->isEmpty()) {
			const Common::Point &mouse = getEventManager()->getMousePos();
			if (_show_overlay) {
				_mouse_texture->drawTexture(mouse.x * cs, mouse.y * cs, _mouse_texture->width(), _mouse_texture->height());
			}
// TODO: Port the non-overlay code as well?
#if 0
			if (_show_overlay) {
			} else {
				const Common::Rect &r = _game_texture->getDrawRect();

				GLCALL(glTranslatex(r.left << 16,
									r.top << 16,
									0));
				GLCALL(glScalex(xdiv(r.width(), _game_texture->width()),
								xdiv(r.height(), _game_texture->height()),
								1 << 16));
			}

			GLCALL(glTranslatex((-_mouse_hotspot.x * cs) << 16,
								(-_mouse_hotspot.y * cs) << 16,
								0));

#endif
	}

	if (!JNI::swapBuffers())
		LOGW("swapBuffers failed: 0x%x", glGetError());

	if (_frame_buffer)
		_frame_buffer->attach();
}
Ejemplo n.º 27
0
void
Canvas::DrawCircle(PixelScalar x, PixelScalar y, UPixelScalar radius)
{
  if (pen_over_brush() && pen.GetWidth() > 2) {
    GLDonutVertices vertices(x, y,
                             radius - pen.GetWidth() / 2,
                             radius + pen.GetWidth() / 2);
    if (!brush.IsHollow()) {
      vertices.bind_inner_circle();
      brush.Set();
      glDrawArrays(GL_TRIANGLE_FAN, 0, vertices.CIRCLE_SIZE);
    }
    vertices.bind();
    pen.Set();
    glDrawArrays(GL_TRIANGLE_STRIP, 0, vertices.SIZE);
  } else if (OpenGL::vertex_buffer_object && radius < 16) {
    /* draw a "small" circle with VBO */

    OpenGL::small_circle_buffer->Bind();
    glVertexPointer(2, GL_SHORT, 0, NULL);

    glPushMatrix();

#ifdef HAVE_GLES
    glTranslatex((GLfixed)x << 16, (GLfixed)y << 16, 0);
    glScalex((GLfixed)radius << 8, (GLfixed)radius << 8, (GLfixed)1 << 16);
#else
    glTranslatef(x, y, 0.);
    glScalef(radius / 256., radius / 256., 1.);
#endif

    if (!brush.IsHollow()) {
      brush.Set();
      glDrawArrays(GL_TRIANGLE_FAN, 0, OpenGL::SMALL_CIRCLE_SIZE);
    }

    if (pen_over_brush()) {
      pen.Bind();
      glDrawArrays(GL_LINE_LOOP, 0, OpenGL::SMALL_CIRCLE_SIZE);
      pen.Unbind();
    }

    glPopMatrix();

    OpenGL::small_circle_buffer->Unbind();
  } else if (OpenGL::vertex_buffer_object) {
    /* draw a "big" circle with VBO */

    OpenGL::circle_buffer->Bind();
    glVertexPointer(2, GL_SHORT, 0, NULL);

    glPushMatrix();

#ifdef HAVE_GLES
    glTranslatex((GLfixed)x << 16, (GLfixed)y << 16, 0);
    glScalex((GLfixed)radius << 6, (GLfixed)radius << 6, (GLfixed)1 << 16);
#else
    glTranslatef(x, y, 0.);
    glScalef(radius / 1024., radius / 1024., 1.);
#endif

    if (!brush.IsHollow()) {
      brush.Set();
      glDrawArrays(GL_TRIANGLE_FAN, 0, OpenGL::CIRCLE_SIZE);
    }

    if (pen_over_brush()) {
      pen.Bind();
      glDrawArrays(GL_LINE_LOOP, 0, OpenGL::CIRCLE_SIZE);
      pen.Unbind();
    }

    glPopMatrix();

    OpenGL::circle_buffer->Unbind();
  } else {
    GLCircleVertices vertices(x, y, radius);
    vertices.bind();

    if (!brush.IsHollow()) {
      brush.Set();
      glDrawArrays(GL_TRIANGLE_FAN, 0, vertices.SIZE);
    }

    if (pen_over_brush()) {
      pen.Bind();
      glDrawArrays(GL_LINE_LOOP, 0, vertices.SIZE);
      pen.Unbind();
    }
  }
}
Ejemplo n.º 28
0
static void ogl_translate(int x, int y) {
	//glTranslatef((float)x, (float)y, 0.0f);
	glTranslatex(x<<16, y<<16, 0);
}
Ejemplo n.º 29
0
/*!
* \brief	Render the OpenGL ES scene.
* \param	time Current time in milliseconds
* \note	Renders the OpenGL ES scene
*//*-------------------------------------------------------------------*/
void renderGLESScene(unsigned int time)
{

    int width = 0;
    int height = 0;
#if defined(TEST_LOCKSURFACE)
    KDuint16 *fb = KD_NULL;
    int y = 0;
    EGLint pitch = 0;
    EGLint origin = 0;
    EGLint r, g, b;
#else
    /* Time needed for the rotation */
    const KDfloat32 effectTime	= kdFmodf(time / 4000.0f, 360.0f);
#endif

    /* Query the current window surface size from EGL */
    eglQuerySurface(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, EGL_WIDTH, (EGLint *)&width);
    eglQuerySurface(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, EGL_HEIGHT, (EGLint *)&height);

#if !defined(TEST_LOCKSURFACE)
    /* Update the GLES state */
    updateOpenGLESState		(width, height);
    glClear 				(GL_COLOR_BUFFER_BIT);

    /* Rotate the world matrix and translate it on the z-axis */
    glMatrixMode			(GL_MODELVIEW);
    glLoadIdentity			();
    glTranslatex			(F2F(0.f), F2F(0.f), F2F(-30.f));
    glRotatex				(F2F((float)(effectTime*29.77f)), F2F(1.0f), F2F(2.0f), F2F(0.0f));
    glRotatex				(F2F((float)(effectTime*22.311f)), F2F(-0.1f), F2F(0.0f), -F2F(5.0f));

    glBindTexture(GL_TEXTURE_2D, GLOBALS->tex);

    /* Set the pointer to the arrays containing the cube vertices, normals 
    and texture coordinates */
    glVertexPointer			(3, GL_BYTE, 0, s_cubeVertices);
    glNormalPointer			(GL_BYTE, 0, s_cubeNormals);
    glTexCoordPointer		(2, GL_BYTE, 0, s_cubeTexCoords);

    /* Draw the cube one face at a time in the same order thay have been defined 
    in the s_cubeVertices array */
    glDrawArrays			(GL_TRIANGLE_STRIP, 0, 4);
    glDrawArrays			(GL_TRIANGLE_STRIP, 4, 4);
    glDrawArrays			(GL_TRIANGLE_STRIP, 8, 4);
    glDrawArrays			(GL_TRIANGLE_STRIP, 12, 4);
    glDrawArrays			(GL_TRIANGLE_STRIP, 16, 4);
    glDrawArrays			(GL_TRIANGLE_STRIP, 20, 4);

#else

    /* Lock the surface and query for the properties */
    eglLockSurfaceKHR(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, KD_NULL);
    eglQuerySurface(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, EGL_BITMAP_POINTER_KHR, (EGLint *)&fb);
    eglQuerySurface(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, EGL_BITMAP_PITCH_KHR, &pitch);
    eglQuerySurface(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, EGL_BITMAP_ORIGIN_KHR, &origin);
    eglQuerySurface(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, EGL_BITMAP_PIXEL_RED_OFFSET_KHR, &r);
    eglQuerySurface(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR, &g);
    eglQuerySurface(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface, EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR, &b);

    /* Fill the surface with random noise */
    for(y = 0; y < height; y++)
    {
        kdCryptoRandom((KDuint8 *)fb, width * 2);
        fb += pitch / 2;
    }

    eglUnlockSurfaceKHR(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface);
#endif

    /* Display the result on the screen */
    eglSwapBuffers			(GLOBALS->eglDisplay, GLOBALS->eglWindowSurface);

}