Пример #1
0
// ----------------------------------------------------------------------------
void
vertex_buffer_render_setup ( vertex_buffer_t *self,
                             GLenum mode, const char *what )
{
    if( self->state != CLEAN )
    {
        vertex_buffer_upload( self );
        self->state = CLEAN;
    }
    
    glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
    glBindBuffer( GL_ARRAY_BUFFER, self->vertices_id );

    size_t i;
    for( i=0; i<MAX_VERTEX_ATTRIBUTE; ++i )
    {
        vertex_attribute_t *attribute = self->attributes[i];
        if ( attribute == 0 )
        {
            break;
        }
        else
        {
            if (attribute->ctarget == 'g')
            {
                (*(attribute->enable))( attribute );
            }
            else if ( strchr(what, attribute->ctarget) )
            {
                (*(attribute->enable))( attribute );
            }
        }
    }
    if( self->indices->size )
    {
        glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, self->indices_id );
    }
    self->mode = mode;
}
Пример #2
0
void ResourceBrowseWnd::Render() {
    GG::Pt ul = UpperLeft();

    glPushMatrix();
    glLoadIdentity();
    glTranslatef(static_cast<GLfloat>(Value(m_offset.x + ul.x)), static_cast<GLfloat>(Value(m_offset.y + ul.y)), 0.0f);
    glDisable(GL_TEXTURE_2D);
    glLineWidth(1.0);
    glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
    glEnableClientState(GL_VERTEX_ARRAY);

    m_buffer.activate();
    glColor(ClientUI::WndColor());
    glDrawArrays(GL_TRIANGLE_FAN,   2, 4);
    glColor(ClientUI::WndOuterBorderColor());
    glDrawArrays(GL_LINE_LOOP,      2, 4);
    glDrawArrays(GL_TRIANGLE_FAN,   0, 4);

    glEnable(GL_TEXTURE_2D);
    glPopMatrix();
    glPopClientAttrib();
}
Пример #3
0
void PartlyRoundedRect(const GG::Pt& ul, const GG::Pt& lr, int radius, bool ur_round, bool ul_round,
                       bool ll_round, bool lr_round, bool fill)
{
    GG::GL2DVertexBuffer vert_buf;
    vert_buf.reserve(210);  // should be enough for 4 corners with 50 verts each, plus a bit extra to be safe

    BufferStorePartlyRoundedRectVertices(vert_buf, ul, lr, radius, ur_round, lr_round, ll_round, lr_round);

    //glDisable(GL_TEXTURE_2D);
    glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
    glEnableClientState(GL_VERTEX_ARRAY);

    vert_buf.activate();

    if (fill)
        glDrawArrays(GL_TRIANGLE_FAN, 0, vert_buf.size());
    else
        glDrawArrays(GL_LINE_LOOP, 0, vert_buf.size());

    glPopClientAttrib();
    //glEnable(GL_TEXTURE_2D);
}
Пример #4
0
static void render(struct glpal_ctx *ctx, GLuint draw_tex)
{DEBUG_CHECK_GL_ERR;
	static const float verts[] = {
		0, 0 , -1, -1,
		1, 0 ,  1, -1,
		0, 1 , -1,  1,
		1, 1 ,  1,  1
	};
	struct priv_ctx *priv = (struct priv_ctx *)ctx;

	

	glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
	glUseProgramObjectARB(priv->prog);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, draw_tex);
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_1D, priv->tex[priv->cnt]);

	glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, pal_ctx_get_active(priv->pal));

	priv->cnt = (priv->cnt+1)%2;

	glBindTexture(GL_TEXTURE_1D, priv->tex[priv->cnt]);

	glEnableVertexAttribArrayARB(0);
	glVertexAttribPointerARB(0, 4, GL_FLOAT, GL_FALSE, sizeof(float)*4, verts);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	glUseProgramObjectARB(0);
	glDisableVertexAttribArrayARB(0);
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_1D, 0);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, 0);
	glPopClientAttrib();

	DEBUG_CHECK_GL_ERR;
}
Пример #5
0
void FTGLPixmapFont::Render( const wchar_t* string) {
	glPushAttrib( GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT);
	glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT);
	
	glEnable(GL_BLEND);
	glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	glDisable( GL_TEXTURE_2D);
	
	GLfloat ftglColour[4];
	glGetFloatv( GL_CURRENT_RASTER_COLOR, ftglColour);
	
	glPixelTransferf(GL_RED_SCALE, ftglColour[0]);
	glPixelTransferf(GL_GREEN_SCALE, ftglColour[1]);
	glPixelTransferf(GL_BLUE_SCALE, ftglColour[2]);
	glPixelTransferf(GL_ALPHA_SCALE, ftglColour[3]);
	
	FTFont::Render( string);
	
	glPopClientAttrib();
	glPopAttrib();
}
Пример #6
0
bool GLWidgetRenderStrategy::render(Content* content, Image* renderImage)
{
    if (!renderImage)
        return false;

    glWidget->makeCurrent();
    QSize size(renderImage->width(), renderImage->height());
    createFBO(size);

    // Render frame into QGLWidget.
    // This isn't really valid for a hidden QGLWidget due to the OpenGL
    // "pixel ownership test". But it works with some graphics drivers.
    QPainter painter(glWidget);
    painter.setRenderHints(QPainter::Antialiasing |
                           QPainter::TextAntialiasing |
                           QPainter::SmoothPixmapTransform, true);
    content->paintContent(&painter);
    painter.end();

    // Blit from QGLWidget to FBO, flipping image vertically
    QRect srcRect(0, 0, renderImage->width(), renderImage->height());
    QRect dstRect(0, renderImage->height(),
                  renderImage->width(), -renderImage->height());
    QGLFramebufferObject::blitFramebuffer(fbo, srcRect, 0, dstRect);

    // Read back the pixels from the FBO
    fbo->bind();
    glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
    glPixelStorei(GL_PACK_ALIGNMENT, 1);
    glPixelStorei(GL_PACK_ROW_LENGTH, renderImage->bytesPerLine() / 3);
    glReadPixels(0, 0, renderImage->width(), renderImage->height(),
                 GL_RGB, GL_UNSIGNED_BYTE, renderImage->pixels());
    glPopClientAttrib();
    fbo->release();
    glWidget->doneCurrent();

    return true;
}
Пример #7
0
void DrawableObject::draw()
{
  for (unsigned int i=0; i<gl_modes.size(); ++i) {
    glEnable(gl_modes[i]);
  }
  glPushMatrix();
  glPushAttrib(GL_ALL_ATTRIB_BITS);
  glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
  if (shader) shader->activate();

  glTranslated(Position[0], Position[1], Position[2]);
  glScaled(Scale[0], Scale[1], Scale[2]);
  glRotated(Orientation[0], 1, 0, 0);
  glRotated(Orientation[1], 0, 1, 0);
  glRotated(Orientation[2], 0, 0, 1);

  glColor4d(Color[0], Color[1], Color[2], Alpha);
  glLineWidth(LineWidth);

  GLfloat mat_diff[] = { 0.9, 0.9, 0.9, Alpha };
  GLfloat mat_spec[] = { 1.0, 1.0, 1.0, Alpha };
  GLfloat mat_shin[] = { 128.0 };

  glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diff);
  glMaterialfv(GL_FRONT, GL_SPECULAR, mat_spec);
  glMaterialfv(GL_FRONT, GL_SHININESS, mat_shin);

  draw_local();
  if (shader) shader->deactivate();

  glPopClientAttrib();
  glPopAttrib();
  glPopMatrix();

  for (unsigned int i=0; i<gl_modes.size(); ++i) {
    glDisable(gl_modes[i]);
  }
}
Пример #8
0
void VAR::uploadToCard(const void* sourcePtr, int dstPtrOffset, size_t size) {
    void* ptr = (void*)(reinterpret_cast<intptr_t>(_pointer) + dstPtrOffset);

    switch (VARArea::mode) {
    case VARArea::VBO_MEMORY:
        // Don't destroy any existing bindings; this call can
        // be made at any time and the program might also
        // use VBO on its own.
        glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
            glBindBufferARB(GL_ARRAY_BUFFER_ARB, area->glbuffer);
            glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, (GLintptrARB)ptr, size, sourcePtr);
            glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
        glPopClientAttrib();
        break;

    case VARArea::MAIN_MEMORY:
        System::memcpy(ptr, sourcePtr, size);
        break;

    default:
        alwaysAssertM(false, "Fell through switch");
    }
}
Пример #9
0
static void drawBackground(const float width, const float height, const float x, const float y)
{
    GLfloat vertices[4][2];
    
    vertices[0][0] = x; vertices[0][1] = y;
    vertices[1][0] = width + x; vertices[1][1] = y;
    vertices[2][0] = width + x; vertices[2][1] = height + y;
    vertices[3][0] = x; vertices[3][1] = height + y;
    
    glLoadIdentity();
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
    glVertexPointer(2, GL_FLOAT, 0, vertices);
    glEnableClientState(GL_VERTEX_ARRAY);
    glColor4f(0.0f, 0.0f, 0.0f, 0.5f);	// 50% transparent black.
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // Opaque white.
    //glLineWidth(1.0f);
    //glDrawArrays(GL_LINE_LOOP, 0, 4);
    glPopClientAttrib();
    glDisable(GL_BLEND);
}
Пример #10
0
	void OpenGLRenderManager::begin()
	{
		glClearColor(0, 0, 0, 1);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glLoadIdentity();

		//save current attributes
		glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
		glPushAttrib(GL_ALL_ATTRIB_BITS);

		glPolygonMode(GL_FRONT, GL_FILL);
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		glOrtho(-1, 1, -1, 1, -1, 1);

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

		glDisable(GL_LIGHTING);
		glDisable(GL_DEPTH_TEST);
		glDisable(GL_FOG);
		glDisable(GL_TEXTURE_GEN_S);
		glDisable(GL_TEXTURE_GEN_T);
		glDisable(GL_TEXTURE_GEN_R);

		//glFrontFace(GL_CW);
		//glCullFace(GL_BACK);
		//glEnable(GL_CULL_FACE);

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

		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		glEnable(GL_TEXTURE_2D);
	}
Пример #11
0
//------------------------------------
void ofImage::grabScreen(int _x, int _y, int _w, int _h){

	if (!myPixels.bAllocated){
		allocate(_w, _h, OF_IMAGE_COLOR);
	}

	int screenHeight = ofGetHeight();
	_y = screenHeight - _y;
	_y -= _h; // top, bottom issues

	if (!((width == _w) && (height == _h))){
		resize(_w, _h);
	}

	#ifndef TARGET_OF_IPHONE
		glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );											// be nice to anyone else who might use pixelStore
	#endif
		glPixelStorei(GL_PACK_ALIGNMENT, 1);														// set read non block aligned...
		glReadPixels(_x, _y, _w, _h, myPixels.glDataType,GL_UNSIGNED_BYTE, myPixels.pixels);		// read the memory....
	#ifndef TARGET_OF_IPHONE
		glPopClientAttrib();
	#endif

	int sizeOfOneLineOfPixels = myPixels.width * myPixels.bytesPerPixel;
	unsigned char * tempLineOfPix = new unsigned char[sizeOfOneLineOfPixels];
	unsigned char * linea;
	unsigned char * lineb;
	for (int i = 0; i < myPixels.height/2; i++){
		linea = myPixels.pixels + i * sizeOfOneLineOfPixels;
		lineb = myPixels.pixels + (myPixels.height-i-1) * sizeOfOneLineOfPixels;
		memcpy(tempLineOfPix, linea, sizeOfOneLineOfPixels);
		memcpy(linea, lineb, sizeOfOneLineOfPixels);
		memcpy(lineb, tempLineOfPix, sizeOfOneLineOfPixels);
	}
	delete [] tempLineOfPix;
	update();
}
Пример #12
0
unsigned int PointCylinder() {
    float* vertices;
    float* colors;
    unsigned int* indices;
    int len_indices, n_segs;

    unsigned int result;

    // PointCylinder
    n_segs = 30;

    vertices=NULL;
    colors=NULL;
    indices=NULL;

    vertices = malloc(3*n_segs*2*sizeof(float));
    colors = malloc(3*n_segs*2*sizeof(float));
    indices = malloc(n_segs*2*sizeof(unsigned int));
    len_indices=n_segs*2;

    make_cyl_data( n_segs, vertices, colors, indices);

    result = 0;
    result = glGenLists(1);
    glNewList(result, GL_COMPILE);

    glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3, GL_FLOAT, 0, vertices);
    glEnableClientState(GL_COLOR_ARRAY);
    glColorPointer(3, GL_FLOAT, 0, colors);
    glDrawElements(GL_POINTS, len_indices, GL_UNSIGNED_INT, indices);
    glPopClientAttrib();

    glEndList();
    return result;
}
Пример #13
0
        void spherical_clipmap::draw(context *c)
        {
            // don't bother drawing on the first frame, as we don't have a modelview yet...
            if (clipmap_rings.size())
            {
                glPushAttrib(GL_ALL_ATTRIB_BITS);
                glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);

                glEnableClientState(GL_VERTEX_ARRAY);
                glEnableClientState(GL_INDEX_ARRAY);

                glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);

                color::WHITE.set();

                for (int i = 0; i <= last_ring; ++i)
                {
                    if (i >= first_ring)
                        clipmap_rings[i]->draw();

                    if (c->render_flags & context::RENDER_WIREFRAME)
                    {
                        if (i % 2)
                            color::WHITE.set();
                        else
                            GRAY.set();
                    }
                }

                clipmap_cap->draw();

                //
                glPopClientAttrib();
                glPopAttrib();
            }
        } // spherical_clipmap::draw()
Пример #14
0
        display::scoped_text::scoped_text(display & parent)
            : parent(parent)
        {
            parent.bind();

            // record 3d info
            glGetIntegerv(GL_VIEWPORT, text_draw_viewport);                                                         CHECK_GL_ERRORS();
            glGetFloatv(GL_MODELVIEW_MATRIX, text_draw_modelview.ptr());                                            CHECK_GL_ERRORS();
            glGetFloatv(GL_PROJECTION_MATRIX, text_draw_projection.ptr());                                          CHECK_GL_ERRORS();
            text_draw_pm = text_draw_projection * text_draw_modelview;                                              CHECK_GL_ERRORS();

            // set up projection and modelview for drawing text
            glPushAttrib(GL_ALL_ATTRIB_BITS);                                                                       CHECK_GL_ERRORS();
            glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);                                                          CHECK_GL_ERRORS();
            
            glMatrixMode(GL_PROJECTION);                                                                            CHECK_GL_ERRORS();
            glPushMatrix();                                                                                         CHECK_GL_ERRORS();
            glLoadIdentity();                                                                                       CHECK_GL_ERRORS();
            glOrtho(0.0, parent.surface->w, 0.0, parent.surface->h, -1, 1);                                         CHECK_GL_ERRORS();

            glMatrixMode(GL_MODELVIEW);                                                                             CHECK_GL_ERRORS();
            glPushMatrix();                                                                                         CHECK_GL_ERRORS();
            glLoadIdentity();                                                                                       CHECK_GL_ERRORS();
        } // display::scoped_text::scoped_text()
Пример #15
0
void UWKRendererGL::InitInternal()
{
    glPushAttrib(GL_ALL_ATTRIB_BITS);
    glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);

    glActiveTexture(GL_TEXTURE0);

    CGLContextObj cgl_ctx = CGLGetCurrentContext();

    if (!setupFrameBuffer())
    {
        glPopClientAttrib();
        glPopAttrib();
        return;
    }

    glGenTextures(1, &surfaceTextureID_);
    glEnable(GL_TEXTURE_RECTANGLE_ARB);
    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, surfaceTextureID_);

    glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

    CGLTexImageIOSurface2D(cgl_ctx, GL_TEXTURE_RECTANGLE_ARB, GL_RGBA, maxWidth_, maxHeight_, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,surfaceRef_, 0);

    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
    glDisable(GL_TEXTURE_RECTANGLE_ARB);

    glPopClientAttrib();
    glPopAttrib();

    // mark as valid
    valid_ = true;
}
Пример #16
0
		static	void	saveOpenGLState(int screenWidth, int screenHeight)
			{
				glPushAttrib(GL_ALL_ATTRIB_BITS);
				glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);

		

				glDisable(GL_TEXTURE_GEN_S);
				glDisable(GL_TEXTURE_GEN_T);
				glDisable(GL_TEXTURE_GEN_R);

				glDisable(GL_LINE_SMOOTH);
			//    glDisable(GL_LINE_STIPPLE);
				glDisable(GL_CULL_FACE);
				glDisable(GL_DEPTH_TEST);
				glDisable(GL_LIGHTING);
				glEnable(GL_BLEND);

				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

				glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
				glDisable(GL_TEXTURE_2D);

			}
Пример #17
0
void Sample_11::initGL()
{
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	// set here server attributes (states)
	glEnable(GL_TEXTURE_2D);                        // Enable Texture Mapping ( NEW )
	glShadeModel(GL_SMOOTH);                        // Enable Smooth Shading
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);                   // Black Background
	glClearDepth(1.0f);                         // Depth Buffer Setup
	glEnable(GL_DEPTH_TEST);                        // Enables Depth Testing
	glDepthFunc(GL_LEQUAL);                         // The Type Of Depth Testing To Do
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);          // Really Nice Perspective
	glPolygonMode( GL_BACK, GL_FILL );          // Back Face Is Filled In
	glPolygonMode( GL_FRONT, GL_LINE );         // Front Face Is Drawn With Lines

	// Typical Texture Generation Using Data From The Bitmap
	glBindTexture(GL_TEXTURE_2D, m_texture[TEX_1]);
	// Generate The Texture
	glTexImage2D(GL_TEXTURE_2D, 0, 3, m_image.sizeY(), m_image.sizeY(), 0, GL_RGB, GL_UNSIGNED_BYTE, m_image.data() );
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering

	glPushClientAttrib(GL_ALL_CLIENT_ATTRIB_BITS);
	// set here client attributes (states)
}
Пример #18
0
void Cylinder::draw(){
	if (!_valid)
	{
		if (!init())
			return;
	}

	glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
	
	// enable and allocate data
	glEnableClientState( GL_VERTEX_ARRAY );
	glEnableClientState( GL_NORMAL_ARRAY );
	glVertexPointer( 3, GL_FLOAT, 0, _vertices );
	glNormalPointer( GL_FLOAT, 0, _normals );

    // draw
	glDrawElements( GL_QUAD_STRIP, _numVerts, GL_UNSIGNED_SHORT, _indices );
	if (_drawCap1)
		glDrawElements( GL_TRIANGLE_FAN, _numCapVerts, GL_UNSIGNED_SHORT, _cap1Start );
	if (_drawCap2)
		glDrawElements( GL_TRIANGLE_FAN, _numCapVerts, GL_UNSIGNED_SHORT, _cap2Start );

	glPopClientAttrib();
}
Пример #19
0
void Sample_20::initGL()
{
	glPushAttrib(GL_ALL_ATTRIB_BITS);

	if (m_texture[TEX_LOGO] == 0)
		glGenTextures(TEX_QTY, &m_texture[TEX_LOGO]);                  // Create The Texture

	for (int loop=0; loop<TEX_QTY; loop++)                 // Loop Through All 5 Textures
	{
		glBindTexture(GL_TEXTURE_2D, m_texture[loop]);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, m_image[loop].sizeY(), m_image[loop].sizeY(), 0, GL_RGB, GL_UNSIGNED_BYTE, m_image[loop].data() );
	}

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);                   // Clear The Background Color To Black
	glClearDepth(1.0);                          // Enables Clearing Of The Depth Buffer
	glEnable(GL_DEPTH_TEST);                        // Enable Depth Testing
	glShadeModel(GL_SMOOTH);                        // Enables Smooth Color Shading
	glEnable(GL_TEXTURE_2D);                        // Enable 2D Texture Mapping

	glPushClientAttrib(GL_ALL_CLIENT_ATTRIB_BITS);
	// set here client attributes (states)
}
Пример #20
0
void ofApp::drawModels() {
    ofSetColor(255);
    
    ofEnableBlendMode(OF_BLENDMODE_ALPHA);
    
	ofEnableDepthTest();
    
    glShadeModel(GL_SMOOTH); //some model / light stuff
    light.enable();
    ofEnableSeparateSpecularLight();


    for (int i = 0; i < models.size(); i++) {
        ofPushMatrix();
        models[i]->drawFaces();
        ofPopMatrix();
    }
    //model.setScale(.3, .3, .3);
    //model.drawFaces();
 
    
    if(ofGetGLProgrammableRenderer()){
		glPushAttrib(GL_ALL_ATTRIB_BITS);
		glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
    }
    glEnable(GL_NORMALIZE);
    
    if(ofGetGLProgrammableRenderer()){
    	glPopAttrib();
    }
    
    ofDisableDepthTest();
    light.disable();
    ofDisableLighting();
    ofDisableSeparateSpecularLight();
}
Пример #21
0
//-----------------------------------------------------------------------------
// Name: beginRenderText()
// Desc: Utility function for using the bitmap-based character fonts defined 
//       above. Call this function to begin rendering text. Call the function 
//       endRenderText to stop.
//-----------------------------------------------------------------------------
void beginRenderText( int nWindowWidth, int nWindowHeight, bool blend )
{
	// Push back and cache the current state of pixel alignment.
	glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );
	glPixelStorei( GL_UNPACK_SWAP_BYTES, GL_FALSE );
	glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE );
	glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
	glPixelStorei( GL_UNPACK_SKIP_ROWS, 0 );
	glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0 );
	glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );

	// Push back and cache the current state of depth testing and lighting
	// and then disable them.
	glPushAttrib( GL_TEXTURE_BIT | GL_DEPTH_TEST | GL_LIGHTING | GL_COLOR_BUFFER_BIT);

	glDisable( GL_TEXTURE_2D );
	glDisable( GL_DEPTH_TEST );
	glDisable( GL_LIGHTING );
	if (blend)
	{
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
	}
	else
		glDisable(GL_BLEND);

	// Push back the current matrices and go orthographic for text rendering.
	glMatrixMode( GL_PROJECTION );
	glPushMatrix();
	glLoadIdentity();
	glOrtho( 0, (double)nWindowWidth, (double)nWindowHeight, 0, -1, 1 );

	glMatrixMode( GL_MODELVIEW );
	glPushMatrix();
	glLoadIdentity();
}
Пример #22
0
static void ogl_unlock_region_non_readonly(ALLEGRO_BITMAP *bitmap,
   ALLEGRO_BITMAP_EXTRA_OPENGL *ogl_bitmap)
{
   const int lock_format = bitmap->locked_region.format;
   const int gl_y = bitmap->h - bitmap->lock_y - bitmap->lock_h;
   ALLEGRO_DISPLAY *old_disp = NULL;
   ALLEGRO_DISPLAY *disp;
   int orig_format;
   bool biased_alpha = false;
   GLenum e;

   disp = al_get_current_display();
   orig_format = _al_get_real_pixel_format(disp, _al_get_bitmap_memory_format(bitmap));

   /* Change OpenGL context if necessary. */
   if (!disp ||
      (_al_get_bitmap_display(bitmap)->ogl_extras->is_shared == false &&
       _al_get_bitmap_display(bitmap) != disp))
   {
      old_disp = disp;
      _al_set_current_display_only(_al_get_bitmap_display(bitmap));
   }

   /* Keep this in sync with ogl_lock_region. */
   glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
   {
      const int lock_pixel_size = al_get_pixel_size(lock_format);
      const int pixel_alignment = ogl_pixel_alignment(lock_pixel_size);
      glPixelStorei(GL_UNPACK_ALIGNMENT, pixel_alignment);
      e = glGetError();
      if (e) {
         ALLEGRO_ERROR("glPixelStorei(GL_UNPACK_ALIGNMENT, %d) failed (%s).\n",
            pixel_alignment, _al_gl_error_string(e));
      }
   }
   if (exactly_15bpp(lock_format)) {
      /* OpenGL does not support 15-bpp internal format without an alpha,
       * so when storing such data we must ensure the alpha bit is set.
       */
      glPixelTransferi(GL_ALPHA_BIAS, 1);
      biased_alpha = true;
   }

   if (ogl_bitmap->is_backbuffer) {
      ALLEGRO_DEBUG("Unlocking backbuffer\n");
      ogl_unlock_region_backbuffer(bitmap, ogl_bitmap, gl_y);
   }
   else {
      glBindTexture(GL_TEXTURE_2D, ogl_bitmap->texture);
      if (ogl_bitmap->fbo_info) {
         ALLEGRO_DEBUG("Unlocking non-backbuffer (FBO)\n");
         ogl_unlock_region_nonbb_fbo(bitmap, ogl_bitmap, gl_y, orig_format);
      }
      else {
         ALLEGRO_DEBUG("Unlocking non-backbuffer (non-FBO)\n");
         ogl_unlock_region_nonbb_nonfbo(bitmap, ogl_bitmap, gl_y);
      }

      /* If using FBOs, we need to regenerate mipmaps explicitly now. */
      /* XXX why don't we check ogl_bitmap->fbo_info? */
      if ((al_get_bitmap_flags(bitmap) & ALLEGRO_MIPMAP) &&
         al_get_opengl_extension_list()->ALLEGRO_GL_EXT_framebuffer_object)
      {
         glGenerateMipmapEXT(GL_TEXTURE_2D);
         e = glGetError();
         if (e) {
            ALLEGRO_ERROR("glGenerateMipmapEXT for texture %d failed (%s).\n",
               ogl_bitmap->texture, _al_gl_error_string(e));
         }
      }
   }

   if (biased_alpha) {
      glPixelTransferi(GL_ALPHA_BIAS, 0);
   }
   glPopClientAttrib();

   if (old_disp) {
      _al_set_current_display_only(old_disp);
   }
}
Пример #23
0
ALLEGRO_LOCKED_REGION *_al_ogl_lock_region_new(ALLEGRO_BITMAP *bitmap,
   int x, int y, int w, int h, int format, int flags)
{
   ALLEGRO_BITMAP_EXTRA_OPENGL * const ogl_bitmap = bitmap->extra;
   const GLint gl_y = bitmap->h - y - h;
   ALLEGRO_DISPLAY *disp;
   ALLEGRO_DISPLAY *old_disp = NULL;
   GLenum e;

   if (format == ALLEGRO_PIXEL_FORMAT_ANY) {
      format = bitmap->format;
   }

   disp = al_get_current_display();
   format = _al_get_real_pixel_format(disp, format);

   /* Change OpenGL context if necessary. */
   if (!disp ||
      (bitmap->display->ogl_extras->is_shared == false &&
       bitmap->display != disp))
   {
      old_disp = disp;
      _al_set_current_display_only(bitmap->display);
   }

   /* Set up the pixel store state.  We will need to match it when unlocking.
    * There may be other pixel store state we should be setting.
    * See also pitfalls 7 & 8 from:
    * http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/
    */
   glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
   {
      const int pixel_size = al_get_pixel_size(format);
      const int pixel_alignment = ogl_pixel_alignment(pixel_size);
      glPixelStorei(GL_PACK_ALIGNMENT, pixel_alignment);
      e = glGetError();
      if (e) {
         ALLEGRO_ERROR("glPixelStorei(GL_PACK_ALIGNMENT, %d) failed (%s).\n",
            pixel_alignment, _al_gl_error_string(e));
      }
   }

   if (ogl_bitmap->is_backbuffer) {
      ALLEGRO_DEBUG("Locking backbuffer\n");
      ogl_lock_region_backbuffer(bitmap, ogl_bitmap,
         x, gl_y, w, h, format, flags);
   }
   else if (flags & ALLEGRO_LOCK_WRITEONLY) {
      ALLEGRO_DEBUG("Locking non-backbuffer WRITEONLY\n");
      ogl_lock_region_nonbb_writeonly(bitmap, ogl_bitmap,
         x, gl_y, w, h, format);
   }
   else {
      ALLEGRO_DEBUG("Locking non-backbuffer READWRITE\n");
      ogl_lock_region_nonbb_readwrite(bitmap, ogl_bitmap,
         x, gl_y, w, h, format);
   }

   glPopClientAttrib();

   if (old_disp != NULL) {
      _al_set_current_display_only(old_disp);
   }

   return &bitmap->locked_region;
}
Пример #24
0
/////////////////////////////////////
// draw_start()
/////////////////////////////////////
void
ProxyStroke::draw_start()
{
   // Push affected state:
   glPushAttrib(
      GL_CURRENT_BIT            |
      GL_ENABLE_BIT             |
      GL_COLOR_BUFFER_BIT       |
      GL_TEXTURE_BIT
      );

   glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);

   // Set state for drawing strokes:
   glDisable(GL_LIGHTING);      // GL_ENABLE_BIT
   glDisable(GL_CULL_FACE);     // GL_ENABLE_BIT
   if (!_use_depth)  
      glDisable(GL_DEPTH_TEST); // GL_ENABLE_BIT
   glEnable(GL_BLEND);          // GL_ENABLE_BIT
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_COLOR_BUFFER_BIT

   // Enable or disable texturing:
   if (_tex) {
      glEnable(GL_TEXTURE_2D);  // GL_ENABLE_BIT
      _tex->apply_texture();    // GL_TEXTURE_BIT
   } else {
      glDisable(GL_TEXTURE_2D); // GL_ENABLE_BIT
   }

   glEnableClientState(GL_VERTEX_ARRAY); //GL_CLIENT_VERTEX_ARRAY_BIT)
   glEnableClientState(GL_COLOR_ARRAY);  //GL_CLIENT_VERTEX_ARRAY_BIT)
   if (_tex)
      glEnableClientState(GL_TEXTURE_COORD_ARRAY);//GL_CLIENT_VERTEX_ARRAY_BIT)

   // Set projection and modelview matrices for drawing in NDC:
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   glLoadMatrixd(VIEW::peek()->ndc_proj().transpose().matrix());

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

   // Cache view related info:
   if (_stamp != VIEW::stamp()) {
      _stamp = VIEW::stamp();
      int w, h;
      VIEW_SIZE(w, h);
      _scale = (float)VIEW::pix_to_ndc_scale();
      
      _max_x = w*_scale/2;
      _max_y = h*_scale/2;
      
      _cam = VIEW::peek_cam()->data()->from();
      _cam_at_v = VIEW::peek_cam()->data()->at_v();
      
      _strokes_drawn = 0;
   }
   
   GLSLPaperShader::begin_glsl_paper(_p);  
}
Пример #25
0
/**
* Renders a string of text using this face
* Returns the width of the rendered text in pixels (at subpixel accuracy)
*/
float
STFont::DrawString(const std::string& str, const STColor4f& color)
{
    if (str.length() == 0 || mImpl->ftFace == NULL)
        return 0.0f;

    //
    // Set up OpenGL state for rendering text, and push
    // attributes so that we can restore when done.
    //
    glPushAttrib( GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT);
    glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT);

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

    glDisable(GL_TEXTURE_2D);

    glPixelTransferf(GL_RED_SCALE, color.r);
    glPixelTransferf(GL_GREEN_SCALE, color.g);
    glPixelTransferf(GL_BLUE_SCALE, color.b);
    glPixelTransferf(GL_ALPHA_SCALE, color.a);

    glRasterPos2f(0.0f, 0.0f);

    //
    // Draw each character in order.
    //
    float totalAdvance = 0.0f;
    unsigned int useKerning = FT_HAS_KERNING(mImpl->ftFace);

    // Render glyph for each character in the string
    int strLength = (int)str.length();
    for (int i=0; i<strLength; i++) {

        unsigned int ch = str[i];

        int bitmapIndex = GetBitmapIndex( ch );

        // Pixmap for this character hasn't been generated.  Do that now.
        if (bitmapIndex == -1) {
            if (ch == ' ') {
                glBitmap( 0, 0, 0.0f, 0.0f, (float) mImpl->size / 4.0f, 0.0f, (const GLubyte*)0 );
                totalAdvance += (float) mImpl->size / 4.0f;
                continue;
            } 
            else {
                bitmapIndex = GenerateBitmap( ch );
            }
        }

        STBitmapGlyph& bitmapGlyph = mImpl->glyphBitmaps[bitmapIndex];
        
        // Move the raster position by (offsetX, offsetY)
        glBitmap(0, 0, 0.0f, 0.0f, (float) bitmapGlyph.offsetX,
                 (float) bitmapGlyph.offsetY, NULL);

        // Render the glyph to the framebuffer
        glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
        glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
        glDrawPixels(bitmapGlyph.width, bitmapGlyph.height,
                     GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,
                     (const GLvoid*) bitmapGlyph.data);
        
        // Restore raster position
        glBitmap(0, 0, 0.0f, 0.0f,
                 (float) -bitmapGlyph.offsetX, (float) -bitmapGlyph.offsetY,
                 NULL);
        
        // Get the kerning offset for the next character.
        FT_Vector kerning = {0,0};
        if( useKerning && (i < strLength-1) ) {
            FT_Get_Kerning(mImpl->ftFace,
                           FT_Get_Char_Index(mImpl->ftFace, str[i] ),
                           FT_Get_Char_Index(mImpl->ftFace, str[i+1] ),
                           0, &kerning );
        }

        // Move the raster position to where it should be for the next character.
        glBitmap(0, 0, 0.0f, 0.0f,
                 (float) (bitmapGlyph.advanceX + kerning.x/64.0f), 0.0f, NULL);

        totalAdvance += bitmapGlyph.advanceX + kerning.x/64.0f;
    }

    //
    // Restore OpenGL state.
    //
    glPopClientAttrib();
    glPopAttrib();

    return totalAdvance;
}
Пример #26
0
//--------------------------------------------------------------
void testApp::draw() {
	glEnable( GL_DEPTH_TEST );
	
	camera.begin();
	
	ofSetLineWidth(1.f);
	if(bDrawDebug) world.drawDebug();
	
	ofEnableLighting();
	light.enable();
	light.setPosition(shapes[0]->getPosition());
	ofSetColor(255, 255, 255);
	shapes[0]->draw();
	
	ofSetColor(100., 100., 100.);
	
	if(!bDropBox) {
		boundsMat.begin();
		for(int i = 0; i < bounds.size()-1; i++) {
			bounds[i]->draw();
		}
		boundsMat.end();
	} else {
		ofNoFill();
		btScalar	m[16];
		ofGetOpenGLMatrixFromRigidBody( boundsShape->getRigidBody(), m );
		glPushMatrix(); 
		glMultMatrixf( m );
		ofBox(ofVec3f(0, 0,0), boundsWidth);
		glPopMatrix();
		ofFill();
	}
	
	ofDisableAlphaBlending();
	ofDisableBlendMode();
	
	glPushAttrib(GL_ALL_ATTRIB_BITS);
    glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
    glEnable(GL_NORMALIZE);
    glDisable(GL_CULL_FACE);
	ofPoint scale		= assimpModel.getScale();
	
	ofSetColor(0, 0, 0);
	logoMat.begin();
	for(int i = 0; i < logos.size(); i++) {
		btScalar	m[16];
		ofGetOpenGLMatrixFromRigidBody( logos[i]->getRigidBody(), m );
		glPushMatrix(); 
		glMultMatrixf( m );
		glTranslatef(-logos[i]->getCentroid().x, -logos[i]->getCentroid().y, -logos[i]->getCentroid().z);
		ofScale(scale.x,scale.y,scale.z);
		assimpModel.getMesh(0).drawFaces();
		glPopMatrix();
	}
	glPopAttrib();
	logoMat.end();
	
	ofSetColor(15,197,138);
	ofPushStyle();
	shapesMat.begin();
	for(int i = 0; i < shapes.size(); i++) {
		shapes[i]->draw();
	}
	shapesMat.end();
	ofPopStyle();
	
	light.disable();
	ofDisableLighting();
	
	camera.end();
	glDisable(GL_DEPTH_TEST);
	
	int totalShapes = shapes.size() + logos.size();
	ofVec3f gravity = world.getGravity();
	stringstream ss;
	ss << "Draw Debug (d): " << bDrawDebug << endl;
	ss << "Total Shapes: " << totalShapes << endl;
	ss << "Add logos(o)" << endl;
	ss << "add spherers (s)" << endl;
	ss << "add boxes (b)" << endl;
	ss << "Gravity(up/down/left/right): x=" << gravity.x << " y= " << gravity.y << " z= " << gravity.z << endl;
	ofSetColor(255, 255, 255);
	ofDrawBitmapString(ss.str().c_str(), 20, 20);
}
Пример #27
0
ALLEGRO_LOCKED_REGION *_al_ogl_lock_region_new(ALLEGRO_BITMAP *bitmap,
   int x, int y, int w, int h, int format, int flags)
{
   ALLEGRO_BITMAP_EXTRA_OPENGL * const ogl_bitmap = bitmap->extra;
   const GLint gl_y = bitmap->h - y - h;
   ALLEGRO_DISPLAY *disp;
   ALLEGRO_DISPLAY *old_disp = NULL;
   ALLEGRO_BITMAP *old_target = al_get_target_bitmap();
   GLenum e;
   bool ok;
   bool restore_fbo = false;

   if (format == ALLEGRO_PIXEL_FORMAT_ANY) {
      /* Never pick compressed formats with ANY, as it interacts weirdly with
       * existing code (e.g. al_get_pixel_size() etc) */
      int bitmap_format = al_get_bitmap_format(bitmap);
      if (_al_pixel_format_is_compressed(bitmap_format)) {
         // XXX Get a good format from the driver?
         format = ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE;
      }
      else {
         format = bitmap_format;
      }
   }

   disp = al_get_current_display();
   format = _al_get_real_pixel_format(disp, format);

   /* Change OpenGL context if necessary. */
   if (!disp ||
      (_al_get_bitmap_display(bitmap)->ogl_extras->is_shared == false &&
       _al_get_bitmap_display(bitmap) != disp))
   {
      old_disp = disp;
      _al_set_current_display_only(_al_get_bitmap_display(bitmap));
   }

   ok = true;

   /* Set up the pixel store state.  We will need to match it when unlocking.
    * There may be other pixel store state we should be setting.
    * See also pitfalls 7 & 8 from:
    * http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/
    */
   glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
   {
      const int pixel_size = al_get_pixel_size(format);
      const int pixel_alignment = ogl_pixel_alignment(pixel_size);
      glPixelStorei(GL_PACK_ALIGNMENT, pixel_alignment);
      e = glGetError();
      if (e) {
         ALLEGRO_ERROR("glPixelStorei(GL_PACK_ALIGNMENT, %d) failed (%s).\n",
            pixel_alignment, _al_gl_error_string(e));
         ok = false;
      }
   }

   if (ok) {
      if (ogl_bitmap->is_backbuffer) {
         ALLEGRO_DEBUG("Locking backbuffer\n");
         ok = ogl_lock_region_backbuffer(bitmap, ogl_bitmap,
            x, gl_y, w, h, format, flags);
      }
      else if (flags & ALLEGRO_LOCK_WRITEONLY) {
         ALLEGRO_DEBUG("Locking non-backbuffer WRITEONLY\n");
         ok = ogl_lock_region_nonbb_writeonly(bitmap, ogl_bitmap,
            x, gl_y, w, h, format);
      }
      else {
         ALLEGRO_DEBUG("Locking non-backbuffer READWRITE\n");
         ok = ogl_lock_region_nonbb_readwrite(bitmap, ogl_bitmap,
            x, gl_y, w, h, format, &restore_fbo);
      }
   }

   glPopClientAttrib();

   /* Restore state after switching FBO. */
   if (restore_fbo) {
      if (!old_target) {
         /* Old target was NULL; release the context. */
         _al_set_current_display_only(NULL);
      }
      else if (!_al_get_bitmap_display(old_target)) {
         /* Old target was memory bitmap; leave the current display alone. */
      }
      else if (old_target != bitmap) {
         /* Old target was another OpenGL bitmap. */
         _al_ogl_setup_fbo(_al_get_bitmap_display(old_target), old_target);
      }
   }

   ASSERT(al_get_target_bitmap() == old_target);

   if (old_disp != NULL) {
      _al_set_current_display_only(old_disp);
   }

   if (ok) {
      return &bitmap->locked_region;
   }

   ALLEGRO_ERROR("Failed to lock region\n");
   ASSERT(ogl_bitmap->lock_buffer == NULL);
   return NULL;
}
void drawTrail(jrPlanet *pPlanet) {

	glDisable(GL_LIGHTING); //lines can't be lit
	glEnable(GL_BLEND); //set up alpha
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
	glEnableClientState(GL_COLOR_ARRAY);

	//because position history loops round, we need to feed LINE_STRIP a consistently ascending or descending array

	//init the array to actually draw
	float afDrawable[iHistoryMax] = {};

	//get the point just after the last recorded position
	int firstStart = pPlanet->iHistoryCount + 3;
	int firstCount = g_iHistoryVariableLength; //up till the end of the history

	//get the start of the array
	int secondStart = 0;
	int secondCount = pPlanet->iHistoryCount; //up to the last recorded position

	//create a new array from those points in the original array
	int iCurrentDrawablePoint = 0;
	for (int j = firstStart; j < firstCount; j++) {
		afDrawable[iCurrentDrawablePoint] = pPlanet->afPositionHistory[j];
		iCurrentDrawablePoint++;
	}

	for (int j = secondStart; j < secondCount; j++) {
		afDrawable[iCurrentDrawablePoint] = pPlanet->afPositionHistory[j];
		iCurrentDrawablePoint++;
	}

	//and then pass it to be drawn
	glVertexPointer(3, GL_FLOAT, 0, afDrawable);

	//we also calculate the alpha so that we can have a fading trail
	float afColour[(iHistoryMax + (iHistoryMax / 3))];

	float iAlpha = 0.0f;

	for (int i = 0; i < (iHistoryMax + (iHistoryMax / 3)); i++) {
		afColour[i] = pPlanet->afDiffuse[0];
		afColour[++i] = pPlanet->afDiffuse[1];
		afColour[++i] = pPlanet->afDiffuse[2];
		if (iAlpha > 0.7f) {
			afColour[++i] = 0.7f;
		}
		else {
			iAlpha += 0.001f;
			afColour[++i] = iAlpha;
		}
	}

	glColorPointer(4, GL_FLOAT, 0, afColour);

	//if there are particle effects for the planet, then we draw those instead of a trail
	if (g_bParticlesOn && pPlanet->m_bParticles) {

		float afPoints[iHistoryMax];

		for (int i = 0; i < iCurrentDrawablePoint; i++) {
			afPoints[i] = afDrawable[i] - randFloat(pPlanet->fSize/2* -1, pPlanet->fSize/2 + 10.0f);
			afPoints[++i] = afDrawable[i] + randFloat(pPlanet->fSize/2* -1, pPlanet->fSize/2 + 10.0f);
			afPoints[++i] = afDrawable[i] + randFloat(pPlanet->fSize/2 * -1, pPlanet->fSize/2 + 10.0f);
		}

		glVertexPointer(3, GL_FLOAT, 0, afPoints);

		glDrawArrays(GL_POINTS, 0, iCurrentDrawablePoint / 3);
	}
	else {
		glDrawArrays(GL_LINE_STRIP, 0, iCurrentDrawablePoint / 3);
	}

	glPopClientAttrib();
}
Пример #29
0
void ofImage_<PixelType>::grabScreen(int _x, int _y, int _w, int _h){

	allocate(_w, _h, OF_IMAGE_COLOR);

    int sw = ofGetViewportWidth();
    int sh = ofGetViewportHeight();     // if we are in a FBO or other viewport, this fails: ofGetHeight();
    
	if (!((width == _w) && (height == _h))){
		resize(_w, _h);
	}

	#ifndef TARGET_OPENGLES
    
    _y = sh - _y;
    _y -= _h; // top, bottom issues
    
    glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );											// be nice to anyone else who might use pixelStore
    glPixelStorei(GL_PACK_ALIGNMENT, 1);
    glReadPixels(_x, _y, _w, _h, ofGetGlInternalFormat(pixels), GL_UNSIGNED_BYTE, pixels.getPixels()); // read the memory....
    glPopClientAttrib();
    
	int sizeOfOneLineOfPixels = pixels.getWidth() * pixels.getBytesPerPixel();
	PixelType * tempLineOfPix = new PixelType[sizeOfOneLineOfPixels];
	PixelType * linea;
	PixelType * lineb;
	for (int i = 0; i < pixels.getHeight()/2; i++){
		linea = pixels.getPixels() + i * sizeOfOneLineOfPixels;
		lineb = pixels.getPixels() + (pixels.getHeight()-i-1) * sizeOfOneLineOfPixels;
		memcpy(tempLineOfPix, linea, sizeOfOneLineOfPixels);
		memcpy(linea, lineb, sizeOfOneLineOfPixels);
		memcpy(lineb, tempLineOfPix, sizeOfOneLineOfPixels);
	}
	delete [] tempLineOfPix;
	
    #else
    
    int numPixels   = width*height;
    if( numPixels == 0 ){
        ofLog(OF_LOG_ERROR, "grabScreen width or height is 0 - returning");
        return;
    }
    
    int numRGBA         = numPixels*4;
    GLubyte *bufferRGBA = (GLubyte *) malloc(numRGBA);

    if(ofGetOrientation() == OF_ORIENTATION_DEFAULT) {
        
        _y = sh - _y;   // screen is flipped vertically.
        _y -= _h;
        
        glPixelStorei(GL_PACK_ALIGNMENT, 1);
        glReadPixels(_x, _y, _w, _h, GL_RGBA, GL_UNSIGNED_BYTE, bufferRGBA);
        
        for(int y = 0; y < _h; y++){  
            for(int x = 0; x < _w; x++){
                
                int i = y * _w * 3 + x * 3;
                int j = (_h-1-y) * _w * 4 + x * 4;  // rotate 90.
                
                pixels.getPixels()[i]   = bufferRGBA[j];
                pixels.getPixels()[i+1] = bufferRGBA[j+1];
                pixels.getPixels()[i+2] = bufferRGBA[j+2];
            }
        }
    }
    else if(ofGetOrientation() == OF_ORIENTATION_180) {
        
        _x = sw - _x;   // screen is flipped horizontally.
        _x -= _w;
        
        glPixelStorei(GL_PACK_ALIGNMENT, 1);
        glReadPixels(_x, _y, _w, _h, GL_RGBA, GL_UNSIGNED_BYTE, bufferRGBA);
        
        for(int y = 0; y < _h; y++){  
            for(int x = 0; x < _w; x++){
                
                int i = y * _w * 3 + x * 3;
                int j = y * _w * 4 + (_w-1-x) * 4;  // rotate 90.
                
                pixels.getPixels()[i]   = bufferRGBA[j];
                pixels.getPixels()[i+1] = bufferRGBA[j+1];
                pixels.getPixels()[i+2] = bufferRGBA[j+2];
            }
        }
    }
    else if(ofGetOrientation() == OF_ORIENTATION_90_RIGHT) {
        
        int tempW = _w;     // swap width and height.
        _w = _h;
        _h = tempW;
        
        int tempY = _y;     // swap x and y.
        _y = _x;
        _x = tempY;
        
        glPixelStorei(GL_PACK_ALIGNMENT, 1);
        glReadPixels(_x, _y, _w, _h, GL_RGBA, GL_UNSIGNED_BYTE, bufferRGBA);
        
        for(int y = 0; y < _h; y++){  
            for(int x = 0; x < _w; x++){
                
                int i = x * _h * 3 + y * 3;
                int j = y * _w * 4 + x * 4;
                
                pixels.getPixels()[i]   = bufferRGBA[j];
                pixels.getPixels()[i+1] = bufferRGBA[j+1];
                pixels.getPixels()[i+2] = bufferRGBA[j+2];
            }
        }
    }
    else if(ofGetOrientation() == OF_ORIENTATION_90_LEFT) {
        
        int tempW = _w; // swap width and height.
        _w = _h;
        _h = tempW;
        
        int tempY = _y; // swap x and y.
        _y = _x;
        _x = tempY;
        
        _x = sw - _x;   // screen is flipped horizontally.
        _x -= _w;
        
        _y = sh - _y;   // screen is flipped vertically.
        _y -= _h;
        
        glPixelStorei(GL_PACK_ALIGNMENT, 1);
        glReadPixels(_x, _y, _w, _h, GL_RGBA, GL_UNSIGNED_BYTE, bufferRGBA);
        
        for(int y = 0; y < _h; y++){  
            for(int x = 0; x < _w; x++){
                
                int i = x * _h * 3 + y * 3;
                int j = (_h-1-y) * _w * 4 + (_w-1-x) * 4;
                
                pixels.getPixels()[i]   = bufferRGBA[j];
                pixels.getPixels()[i+1] = bufferRGBA[j+1];
                pixels.getPixels()[i+2] = bufferRGBA[j+2];
            }
        }
    }
    
    free(bufferRGBA);    
    
    #endif

	update();
}
Пример #30
0
void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
{
	rctf rect;

	if ((!g->width) || (!g->height))
		return;

	if (g->build_tex == 0) {
		GlyphCacheBLF *gc = font->glyph_cache;

		if (font->max_tex_size == -1)
			glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&font->max_tex_size);

		if (gc->cur_tex == BLF_CURTEX_UNSET) {
			blf_glyph_cache_texture(font, gc);
			gc->x_offs = gc->pad;
			gc->y_offs = 0;
		}

		if (gc->x_offs > (gc->p2_width - gc->max_glyph_width)) {
			gc->x_offs = gc->pad;
			gc->y_offs += gc->max_glyph_height;

			if (gc->y_offs > (gc->p2_height - gc->max_glyph_height)) {
				gc->y_offs = 0;
				blf_glyph_cache_texture(font, gc);
			}
		}

		g->tex = gc->textures[gc->cur_tex];
		g->xoff = gc->x_offs;
		g->yoff = gc->y_offs;

		/* prevent glTexSubImage2D from failing if the character
		 * asks for pixels out of bounds, this tends only to happen
		 * with very small sizes (5px high or less) */
		if (UNLIKELY((g->xoff + g->width)  > gc->p2_width)) {
			g->width  -= (g->xoff + g->width)  - gc->p2_width;
			BLI_assert(g->width > 0);
		}
		if (UNLIKELY((g->yoff + g->height) > gc->p2_height)) {
			g->height -= (g->yoff + g->height) - gc->p2_height;
			BLI_assert(g->height > 0);
		}


		glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
		glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
		glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

		glBindTexture(GL_TEXTURE_2D, g->tex);
		glTexSubImage2D(GL_TEXTURE_2D, 0, g->xoff, g->yoff, g->width, g->height, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap);
		glPopClientAttrib();

		g->uv[0][0] = ((float)g->xoff) / ((float)gc->p2_width);
		g->uv[0][1] = ((float)g->yoff) / ((float)gc->p2_height);
		g->uv[1][0] = ((float)(g->xoff + g->width)) / ((float)gc->p2_width);
		g->uv[1][1] = ((float)(g->yoff + g->height)) / ((float)gc->p2_height);

		/* update the x offset for the next glyph. */
		gc->x_offs += (int)BLI_rctf_size_x(&g->box) + gc->pad;

		gc->rem_glyphs--;
		g->build_tex = 1;
	}

	blf_glyph_calc_rect(&rect, g, x, y);

	if (font->flags & BLF_CLIPPING) {
		/* intentionally check clipping without shadow offset */
		rctf rect_test = rect;
		BLI_rctf_translate(&rect_test, font->pos[0], font->pos[1]);

		if (!BLI_rctf_inside_rctf(&font->clip_rec, &rect_test)) {
			return;
		}
	}

	if (font->tex_bind_state != g->tex) {
		glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state = g->tex));
	}

	if (font->flags & BLF_SHADOW) {
		rctf rect_ofs;
		blf_glyph_calc_rect(&rect_ofs, g,
		                    x + (float)font->shadow_x,
		                    y + (float)font->shadow_y);

		switch (font->shadow) {
			case 3:
				blf_texture3_draw(font->shadow_col, g->uv, rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
				break;
			case 5:
				blf_texture5_draw(font->shadow_col, g->uv, rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
				break;
			default:
				glColor4fv(font->shadow_col);
				blf_texture_draw(g->uv, rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
				break;
		}

		glColor4fv(font->orig_col);
	}

	switch (font->blur) {
		case 3:
			blf_texture3_draw(font->orig_col, g->uv, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
			break;
		case 5:
			blf_texture5_draw(font->orig_col, g->uv, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
			break;
		default:
			blf_texture_draw(g->uv, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
			break;
	}

	return;
}