コード例 #1
0
ファイル: Level.itcm.cpp プロジェクト: xfix/Fireworlds
void Level::render(f32 x, f32 y)
{
	int bx = (x.toint()-128) / 256;
	int by = (y.toint()-96) / 256;
	
	for(int xx = bx-2; xx <= bx+2; xx++)
		for(int yy = by -2; yy  <= by+2; yy++)
		{
			if(xx < 0) continue;
			if(yy < 0) continue;
			if(xx >= 32) continue;
			if(yy >= 32) continue;
			
			renderBlock(xx, yy, x, y, true);
		}

	for(int xx = bx-2; xx <= bx+2; xx++)
		for(int yy = by -2; yy  <= by+2; yy++)
		{
			if(xx < 0) continue;
			if(yy < 0) continue;
			if(xx >= 32) continue;
			if(yy >= 32) continue;
			
			renderBlock(xx, yy, x, y, false);
		}
}
コード例 #2
0
ファイル: BlockTreeWidget.cpp プロジェクト: m0x72/pothos
void BlockTreeWidget::mouseMoveEvent(QMouseEvent *event)
{
    if(!(event->buttons() & Qt::LeftButton))
    {
        QTreeWidget::mouseMoveEvent(event);
        return;
    }
    if((event->pos() - _dragStartPos).manhattanLength() < QApplication::startDragDistance())
    {
        QTreeWidget::mouseMoveEvent(event);
        return;
    }

    //get the block data
    auto blockItem = dynamic_cast<BlockTreeWidgetItem *>(itemAt(_dragStartPos));
    if (not blockItem->getBlockDesc()) return;

    //create a block object to render the image
    auto draw = dynamic_cast<GraphEditorTabs *>(getObjectMap()["editorTabs"])->getCurrentGraphEditor()->getCurrentGraphDraw();
    std::shared_ptr<GraphBlock> renderBlock(new GraphBlock(draw));
    renderBlock->setBlockDesc(blockItem->getBlockDesc());
    renderBlock->prerender(); //precalculate so we can get bounds
    const auto bounds = renderBlock->boundingRect();

    //draw the block's preview onto a mini pixmap
    QPixmap pixmap(bounds.size().toSize()+QSize(2,2));
    pixmap.fill(Qt::transparent);
    QPainter painter(&pixmap);
    painter.translate(-bounds.topLeft()+QPoint(1,1));
    //painter.scale(zoomScale, zoomScale); //TODO get zoomscale from draw
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setRenderHint(QPainter::HighQualityAntialiasing);
    painter.setRenderHint(QPainter::SmoothPixmapTransform);
    renderBlock->render(painter);
    renderBlock.reset();
    painter.end();

    //create the drag object
    auto mimeData = new QMimeData();
    std::ostringstream oss; blockItem->getBlockDesc()->stringify(oss);
    QByteArray byteArray(oss.str().c_str(), oss.str().size());
    mimeData->setData("text/json/pothos_block", byteArray);
    auto drag = new QDrag(this);
    drag->setMimeData(mimeData);
    drag->setPixmap(pixmap);
    drag->setHotSpot(-bounds.topLeft().toPoint());
    drag->exec(Qt::CopyAction | Qt::MoveAction);
}
コード例 #3
0
ファイル: renderer.cpp プロジェクト: minecube/minecube
void Renderer::render() {
    // Clear color and depth buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    // Apply some transformations
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.f, 1.f, 1.f, 500.f);
    glRotatef(-90 + context->player->Rotation.Y, 1.f, 0.f, 0.f);
    glRotatef(context->player->Rotation.Z, 0.f, 0.f, 1.f);
    glTranslatef((-context->player->Pos.X - 0.25f) * 10, (-context->player->Pos.Y - 0.25f) * 10, (-context->player->Pos.Z - 1.6f) * 10);    // Translate The Scene Based On Player Position

    glMatrixMode(GL_MODELVIEW);
    
    glBindTexture(GL_TEXTURE_2D, Texture);

    glEnableClientState( GL_VERTEX_ARRAY );
    //glEnableClientState( GL_NORMAL_ARRAY );
    glEnableClientState( GL_TEXTURE_COORD_ARRAY );
    
    bool wrap = false;
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap ? GL_REPEAT : GL_CLAMP );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap ? GL_REPEAT : GL_CLAMP );

    glVertexPointer( 3, GL_DOUBLE, 0, &vertices[0] );
    //glNormalPointer( GL_DOUBLE, 0, &vertices[0] );
    glTexCoordPointer(2, GL_DOUBLE, 0, &texcoords[0]);
    
    // Loop through blocks and render them
    //for (int i = 0; i < context->world->Blocks.size(); i++)
    //    renderBlock(context->world->Blocks[i]);
    for (std::list<PositionedBlock*>::iterator it = context->world->VisibleBlocks.begin(); it != context->world->VisibleBlocks.end(); ++it)
        renderBlock(*it);
    
    Block *block = new StoneBlock();
    for (std::map<int, Player*>::iterator player = context->socket->Players.begin(); player != context->socket->Players.end(); player++) {
        if (player->first != context->socket->Number) {
            drawCube(block, player->second->Pos.X, player->second->Pos.Y, player->second->Pos.Z, 2.f);
        }
    }

    glDisableClientState(GL_VERTEX_ARRAY);
    //glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
コード例 #4
0
ファイル: tetris.c プロジェクト: mabruraas/tetris
void checkGameState()
{
	renderFrame();
	renderNextBlockFrame();
	
	switch (gameState)
	{
	case 0: // Game play
		printCanvasBlocks();
		drawNextBlock();
		renderBlock();
		break;
	case 1: // Game pause
		drawPauseScreen();
		break;
	case 2: // Game over
		drawGameOverScreen();
		break;
	}
	
	drawInstructions();
	drawScoreboard();
}
コード例 #5
0
void CpuClipmapRenderer::onRender( const ClipmapRenderParameters& renderParameters )
{
    // activate the gpu program:
    //glDisable( GL_LIGHTING );
#ifdef OLD_GEOCLIP
    terrainShader_.activate();

    if( programTextChanged_ )
    {
        reloadShader();
        programTextChanged_ = false;
    }
#else
    _pTerrainShader->activate(renderParameters.drawEnv);
#endif

//    bool useDependentTextureLookup = false;

    if( renderParameters.globalTextureObj != NULL )
    {
        renderParameters.globalTextureObj->activate( renderParameters.drawEnv );
        renderParameters.globalTextureEnv->activate( renderParameters.drawEnv );
    }
    else if( renderParameters.heightColorTexture != NULL )
    {
        // todo: use a different pixel shader here
//        useDependentTextureLookup = true;
        renderParameters.heightColorTexture->activate( renderParameters.drawEnv );
    }

    // render all levels from finest to coarsest:
    const int levelCount = int(levels_.size());

    //		for( int i = 0; i < levelCount; ++i )
    for( int i = 0; i < levelCount; ++i )
    {
        int levelIdx = levelCount - i - 1;

        //std::cerr << "Rendering Level " << levelIdx << std::endl;

        GeometryClipmapLevel& level = geoClipmaps_->getLevel( levelIdx );
        GeometryClipmapLevel* coarserLevel = 0;
        GeometryClipmapLevel* finerLevel = 0;

        if( levelIdx > 0 )
        {
            coarserLevel = &geoClipmaps_->getLevel( levelIdx - 1 );
        }
        if( levelIdx + 1 < levelCount )
        {
            finerLevel = &geoClipmaps_->getLevel( levelIdx + 1 );
        }

        const Color3f& debugColor = getDebugColor( levelIdx );

#ifdef OLD_GEOCLIP
        terrainShader_.setUniform(
            "baseColor0", colorToVector( debugColor ) );

        terrainShader_.setUniform(
            "sampleDistance",
            renderParameters.worldTransform.sampleDistance );

        terrainShader_.setUniform(
            "worldOffset",
            renderParameters.worldTransform.offset );

        terrainShader_.setUniform(
            "heightScale",
            renderParameters.worldTransform.heightScale );

        terrainShader_.setUniform(
            "heightOffset",
            renderParameters.worldTransform.heightOffset );
#else
#ifdef NOTUSED
        _pTerrainShader->setUniformParameter(
            "baseColor0", colorToVector( debugColor ) );
#endif
        _pTerrainShader->addUniformVariable(
            "sampleDistance",
            renderParameters.worldTransform.sampleDistance );

        _pTerrainShader->addUniformVariable(
            "worldOffset",
            renderParameters.worldTransform.offset );

        _pTerrainShader->addUniformVariable(
            "heightScale",
            renderParameters.worldTransform.heightScale );

        _pTerrainShader->addUniformVariable(
            "heightOffset",
            renderParameters.worldTransform.heightOffset );
#endif
        if( renderParameters.showTransitionRegions )
        {
            // todo: add a sensible debug representation..
            drawSampleRectangle( level.getCoveredSampleRect(),
                                 debugColor,
                                 renderParameters.worldTransform );
            //drawSamples( level, Color3f( 0, 1, 0 ) );
            //drawVertices( level, debugColor );
            drawBlendLines( level,
                            debugColor,
                            renderParameters.worldTransform );
        }

        if( !level.isActive )
        {
            continue;
        }
        // only use the finer level, if it is active:
        if( finerLevel && !finerLevel->isActive )
        {
            finerLevel = 0;
        }

        // buildIndices dynamically builds the indices for this level and
        // does frustum culling
        // the method returns false if nothing is visible

        // todo: dont rebuild the indices every time.. just rebuild them if
        // something changed (inside the update() call)

        if( buildIndices( level, finerLevel ) )
        {
            // finally: draw the block:
            renderBlock( level, coarserLevel, renderParameters, debugColor );
        }

        stats_.drawnLevelCount++;
    }

    if( renderParameters.globalTextureObj != NULL )
    {
        renderParameters.globalTextureObj->deactivate(
            renderParameters.drawEnv );
        renderParameters.globalTextureEnv->deactivate(
            renderParameters.drawEnv );
    }
    else if(renderParameters.heightColorTexture != NULL)
    {
        renderParameters.heightColorTexture->deactivate(
            renderParameters.drawEnv );
    }

#ifdef OLD_GEOCLIP
    terrainShader_.deactivate();
#else
    _pTerrainShader->deactivate(renderParameters.drawEnv);
#endif

}
コード例 #6
0
ファイル: cdtoons.cpp プロジェクト: St0rmcrow/scummvm
Graphics::Surface *CDToonsDecoder::decodeImage(Common::SeekableReadStream *stream) {
	uint16 u0 = stream->readUint16BE(); // always 9?
	uint16 frameId = stream->readUint16BE();
	uint16 blocksValidUntil = stream->readUint16BE();
	byte u6 = stream->readByte();
	byte backgroundColor = stream->readByte();
	debugN(5, "CDToons frame %d, size %d, unknown %04x (at 0), blocks valid until %d, unknown 6 is %02x, bkg color is %02x\n",
		frameId, stream->size(), u0, blocksValidUntil, u6, backgroundColor);

	Common::Rect clipRect = readRect(stream);
	debugN(9, "CDToons clipRect: (%d, %d) to (%d, %d)\n",
		clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);

	Common::Rect dirtyRect = readRect(stream);
	debugN(9, "CDToons dirtyRect: (%d, %d) to (%d, %d)\n",
		dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom);

	uint32 flags = stream->readUint32BE();
	if (flags & 0x80)
		error("CDToons: frame already processed?");
	debugN(5, "CDToons flags: %08x\n", flags);

	uint16 blockCount = stream->readUint16BE();
	uint16 blockOffset = stream->readUint16BE();
	debugN(9, "CDToons: %d blocks at 0x%04x\n",
		blockCount, blockOffset);

	// max block id?
	uint16 u32 = stream->readUint16BE();
	debugN(5, "CDToons unknown at 32: %04x\n", u32);

	byte actionCount = stream->readByte();
	byte u35 = stream->readByte();

	uint16 paletteId = stream->readUint16BE();
	byte paletteSet = stream->readByte();
	debugN(9, "CDToons palette id %04x, palette byte %02x\n",
		paletteId, paletteSet);

	byte u39 = stream->readByte();
	uint16 u40 = stream->readUint16BE();
	uint16 u42 = stream->readUint16BE();
	debugN(5, "CDToons: unknown at 35 is %02x, unknowns at 39: %02x, %04x, %04x\n",
		u35, u39, u40, u42);

	Common::Array<CDToonsAction> actions;

	for (uint i = 0; i < actionCount; i++) {
		CDToonsAction action;
		action.blockId = stream->readUint16BE();
		action.rect = readRect(stream);
		debugN(9, "CDToons action: render block %d at (%d, %d) to (%d, %d)\n",
			action.blockId, action.rect.left, action.rect.top, action.rect.right, action.rect.bottom);
		actions.push_back(action);
	}

	if (stream->pos() > blockOffset)
		error("CDToons header ended at 0x%08x, but blocks should have started at 0x%08x",
			stream->pos(), blockOffset);

	if (stream->pos() != blockOffset)
		error("CDToons had %d unknown bytes after header", blockOffset - stream->pos());

	for (uint i = 0; i < blockCount; i++) {
		uint16 blockId = stream->readUint16BE();
		if (blockId >= 1200)
			error("CDToons: block id %d was too high", blockId);
		if (_blocks.contains(blockId))
			error("CDToons: new block %d was already seen", blockId);

		CDToonsBlock block;
		block.flags = stream->readUint16BE();
		// flag 1 = palette, flag 2 = data?
		if (block.flags & 0x8000)
			error("CDToons: block already processed?");
		block.size = stream->readUint32BE();
		if (block.size < 14)
			error("CDToons: block size was %d, too small", block.size);
		block.size -= 14;
		block.startFrame = stream->readUint16BE();
		block.endFrame = stream->readUint16BE();
		block.unknown12 = stream->readUint16BE();
		block.data = new byte[block.size];
		stream->read(block.data, block.size);

		debugN(9, "CDToons block id 0x%04x of size 0x%08x, flags %04x, from frame %d to %d, unknown at 12 is %04x\n",
			blockId, block.size, block.flags, block.startFrame, block.endFrame, block.unknown12);

		_blocks[blockId] = block;
	}

	byte xFrmBegin = 0, xFrmCount;
	Common::Array<CDToonsDiff> diffs;

	while (true) {
		int32 nextPos = stream->pos();
		uint32 tag = stream->readUint32BE();
		uint32 size = stream->readUint32BE();
		nextPos += size;

		switch (tag) {
		case MKTAG('D','i','f','f'):
			{
			debugN(5, "CDToons: Diff\n");
			uint16 count = stream->readUint16BE();

			Common::Rect diffClipRect = readRect(stream);
			debugN(9, "CDToons diffClipRect: (%d, %d) to (%d, %d)\n",
				diffClipRect.left, diffClipRect.top, diffClipRect.right, diffClipRect.bottom);

			debugN(5, "CDToons Diff: %d subentries\n", count);
			for (uint i = 0; i < count; i++) {
				CDToonsDiff diff;

				diff.rect = readRect(stream);
				diff.size = stream->readUint32BE();
				if (diff.size < 20)
					error("CDToons: Diff block size was %d, too small", diff.size);

				uint16 diffWidth = stream->readUint16BE();
				uint16 diffHeight = stream->readUint16BE();
				uint16 unknown16 = stream->readUint16BE();
				uint16 unknown18 = stream->readUint16BE();
				diff.size -= 8;

				if (diffWidth != diff.rect.width() || diffHeight != diff.rect.height())
					error("CDToons: Diff sizes didn't match");
				debugN(5, "CDToons Diff: size %d, frame from (%d, %d) to (%d, %d), unknowns %04x, %04x\n",
					diff.size, diff.rect.left, diff.rect.top, diff.rect.right, diff.rect.bottom,
					unknown16, unknown18);

				diff.data = new byte[diff.size];
				stream->read(diff.data, diff.size);
				diffs.push_back(diff);
			}
			}
			break;
		case MKTAG('X','F','r','m'):
			{
			debugN(5, "CDToons: XFrm\n");
			if (!(flags & 0x10))
				error("CDToons: useless XFrm?");

			if (xFrmBegin)
				error("CDToons: duplicate XFrm");
			xFrmBegin = stream->readByte();
			xFrmCount = stream->readByte();
			debugN(9, "CDToons XFrm: run %d actions from %d\n", xFrmCount, xFrmBegin - 1);

			// TODO: don't ignore (if xFrmCount is non-zero)
			Common::Rect dirtyRectXFrm = readRect(stream);
			debugN(9, "CDToons XFrm dirtyRect: (%d, %d) to (%d, %d)\n",
				dirtyRectXFrm.left, dirtyRectXFrm.top, dirtyRectXFrm.right, dirtyRectXFrm.bottom);

			// always zero?
			Common::Rect dirtyRect2XFrm = readRect(stream);
			debugN(9, "CDToons XFrm dirtyRect2: (%d, %d) to (%d, %d)\n",
				dirtyRect2XFrm.left, dirtyRect2XFrm.top, dirtyRect2XFrm.right, dirtyRect2XFrm.bottom);
			}
			break;
		case MKTAG('M','r','k','s'):
			debugN(5, "CDToons: Mrks\n");
			if (!(flags & 0x2))
				error("CDToons: useless Mrks?");

			// TODO
			warning("CDToons: encountered Mrks, not implemented yet");
			break;
		case MKTAG('S','c','a','l'):
			// TODO
			warning("CDToons: encountered Scal, not implemented yet");
			break;
		case MKTAG('W','r','M','p'):
			warning("CDToons: encountered WrMp, ignoring");
			break;
		case MKTAG('F','r','t','R'):
			{
			debugN(5, "CDToons: FrtR\n");
			if (!(flags & 0x40))
				error("CDToons: useless FrtR?");

			uint16 count = stream->readUint16BE();
			debugN(9, "CDToons FrtR: %d dirty rectangles\n", count);
			for (uint i = 0; i < count; i++) {
				Common::Rect dirtyRectFrtR = readRect(stream);
				debugN(9, "CDToons FrtR dirtyRect: (%d, %d) to (%d, %d)\n",
					dirtyRectFrtR.left, dirtyRectFrtR.top, dirtyRectFrtR.right, dirtyRectFrtR.bottom);
			}
			}
			break;
		case MKTAG('B','c','k','R'):
			{
			debugN(5, "CDToons: BckR\n");
			if (!(flags & 0x20))
				error("CDToons: useless BckR?");

			uint16 count = stream->readUint16BE();
			debugN(9, "CDToons BckR: %d subentries\n", count);
			for (uint i = 0; i < count; i++) {
				Common::Rect dirtyRectBckR = readRect(stream);
				debugN(9, "CDToons BckR dirtyRect: (%d, %d) to (%d, %d)\n",
					dirtyRectBckR.left, dirtyRectBckR.top, dirtyRectBckR.right, dirtyRectBckR.bottom);
			}
			}
			break;
		default:
			warning("Unknown CDToons tag '%s'", tag2str(tag));
		}

		if (stream->pos() > nextPos)
			error("CDToons ran off the end of a block while reading it (at %d, next block at %d)",
				stream->pos(), nextPos);
		if (stream->pos() != nextPos) {
			warning("CDToons had %d unknown bytes after block", nextPos - stream->pos());
			stream->seek(nextPos);
		}

		if (stream->pos() == stream->size())
			break;
	}

	for (uint i = 0; i < diffs.size(); i++) {
		renderBlock(diffs[i].data, diffs[i].size, diffs[i].rect.left, diffs[i].rect.top, diffs[i].rect.width(), diffs[i].rect.height());
		delete[] diffs[i].data;
	}
	if (!diffs.empty())
		return _surface;

	for (uint i = 0; i < actions.size(); i++) {
		CDToonsAction &action = actions[i];
		if (i == 0 && action.blockId == 0)
			memset(_surface->pixels, backgroundColor, _surface->w * _surface->h);
		if (!_blocks.contains(action.blockId))
			continue;
		if (!action.rect.right)
			continue;
		if (i == 0 && !diffs.empty())
			continue;

		CDToonsBlock &block = _blocks[action.blockId];
		uint16 width = READ_BE_UINT16(block.data + 2);
		uint16 height = READ_BE_UINT16(block.data);

		renderBlock(block.data + 14, block.size - 14, action.rect.left, action.rect.top, width, height);
	}

	if (paletteId && _currentPaletteId != paletteId) {
		if (!_blocks.contains(paletteId))
			error("CDToons: no block for palette %04x", paletteId);
		if (_blocks[paletteId].size != 2 * 3 * 256)
			error("CDToons: palette %04x is wrong size (%d)", paletteId, _blocks[paletteId].size);

		_currentPaletteId = paletteId;
		if (!paletteSet)
			setPalette(_blocks[paletteId].data);
	}

	return _surface;
}