本文整理汇总了C++中MEngine::getRenderingContext方法的典型用法代码示例。如果您正苦于以下问题:C++ MEngine::getRenderingContext方法的具体用法?C++ MEngine::getRenderingContext怎么用?C++ MEngine::getRenderingContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MEngine
的用法示例。
在下文中一共展示了MEngine::getRenderingContext方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: graphicLoop
void MaratisPlayer::graphicLoop(void)
{
MWindow * window = MWindow::getInstance();
MEngine * engine = MEngine::getInstance();
MRenderingContext * render = engine->getRenderingContext();
// game
MGame * game = engine->getGame();
if(game)
{
if(game->isRunning())
{
render->disableScissorTest();
render->setViewport(0, 0, window->getWidth(), window->getHeight());
game->draw();
}
else
{
render->clear(M_BUFFER_COLOR);
}
}
else
{
render->clear(M_BUFFER_COLOR);
}
}
示例2: Generate
void Atlas::Generate(bool clear)
{
m_Atlas.create(M_UBYTE, m_Width, m_Height, m_BPP);
unsigned char col[]= {255, 255, 255, 0};
for(uint32 x = 0; x < m_Width; ++x)
for(uint32 y = 0; y < m_Height; ++y)
m_Atlas.writePixel(x, y, col);
for(imageMapIter iImage = m_Images.begin();
iImage != m_Images.end();
iImage++)
WriteImage(iImage->second);
MEngine* engine = MEngine::getInstance();
MRenderingContext* render = engine->getRenderingContext();
if(m_TextureID == 0)
render->createTexture(&m_TextureID);
render->bindTexture(m_TextureID);
render->sendTextureImage(&m_Atlas, false, 1, 0);
if(clear)
{
// remove images
delete [] m_Layout;
m_Layout = NULL;
}
}
示例3: update
void MShaderRef::update(void)
{
MEngine * engine = MEngine::getInstance();
MLevel * level = engine->getLevel();
MRenderingContext * render = engine->getRenderingContext();
char * text = readTextFile(getFilename());
if(text)
{
// gen shader if null
if(m_shaderId == 0)
{
switch(m_type)
{
case M_SHADER_VERTEX:
render->createVertexShader(&m_shaderId);
break;
case M_SHADER_PIXEL:
render->createPixelShader(&m_shaderId);
break;
}
}
// send shader source
render->sendShaderSource(m_shaderId, text);
SAFE_FREE(text);
MFXManager * FXManager = level->getFXManager();
unsigned int i;
unsigned int size = FXManager->getFXRefsNumber();
for(i=0; i<size; i++)
{
MFXRef * FXRef = FXManager->getFXRef(i);
if((FXRef->getPixelShaderRef() == this) || (FXRef->getVertexShaderRef() == this))
{
unsigned int FXId = FXRef->getFXId();
render->updateFX(FXId);
}
}
}
}
示例4: Select
void Atlas::Select()
{
if(g_Selected == this)
return;
MEngine* engine = MEngine::getInstance();
MRenderingContext* render = engine->getRenderingContext();
Renderer::Flush();
render->enableTexture();
render->setBlendingMode(M_BLENDING_ALPHA);
render->enableBlending();
if(m_TextureID != 0)
{
render->bindTexture(m_TextureID);
//render->sendTextureImage(&m_Atlas, false, 1, 0);
}
g_Selected = this;
}
示例5: update
void MTextureRef::update(void)
{
M_PROFILE_SCOPE(MTextureRef::update);
MEngine * engine = MEngine::getInstance();
MRenderingContext * render = engine->getRenderingContext();
MImage image;
if(engine->getImageLoader()->loadData(getFilename(), &image))
{
if(m_textureId == 0)
render->createTexture(&m_textureId);
m_components = image.getComponents();
m_width = image.getWidth();
m_height = image.getHeight();
// send texture image
render->bindTexture(m_textureId);
render->sendTextureImage(&image, isMipmapEnabled(), 1, 0);
}
}
示例6: draw
void draw(void)
{
MWindow * window = MWindow::getInstance();
MEngine * engine = MEngine::getInstance();
MRenderingContext * render = engine->getRenderingContext();
MGame * game = engine->getGame();
// set basic viewport
render->disableScissorTest();
render->setViewport(0, 0, window->getWidth(), window->getHeight());
if(game)
{
if(game->isRunning())
{
game->draw();
}
}
window->swapBuffer();
}
示例7: Flush
void Flush()
{
g_CurrentColour.set(255, 255, 255, 255);
if(g_Cnt == 0) return;
MEngine* engine = MEngine::getInstance();
MRenderingContext* render = engine->getRenderingContext();
MSystemContext* system = engine->getSystemContext();
unsigned int w, h;
system->getScreenSize(&w, &h);
// set up the "camera"
render->setViewport(0, 0, w, h);
render->setMatrixMode(M_MATRIX_PROJECTION);
render->loadIdentity();
render->setOrthoView(0, w, h, 0, 1.0f, -1.0f);
render->setMatrixMode(M_MATRIX_MODELVIEW);
render->loadIdentity();
// set up arrays
render->enableVertexArray();
render->enableTexCoordArray();
render->enableColorArray();
render->setVertexPointer(M_FLOAT, 3, g_Vertices);
render->setTexCoordPointer(M_FLOAT, 2, g_UVs);
render->setColorPointer(M_UBYTE, 4, g_Colours);
render->disableCullFace();
render->disableDepthTest();
render->drawArray(M_PRIMITIVE_TRIANGLES, 0, g_Cnt * 6);
g_Cnt = 0;
g_Selected = NULL;
}
示例8: drawDisplay
void MFixedRenderer::drawDisplay(MSubMesh * subMesh, MDisplay * display, MVector3 * vertices, MVector3 * normals, MColor * colors)
{
M_PROFILE_SCOPE(MFixedRenderer::drawDisplay);
MEngine * engine = MEngine::getInstance();
MRenderingContext * render = engine->getRenderingContext();
render->setColor4(MVector4(1, 1, 1, 1));
// get material
MMaterial * material = display->getMaterial();
{
float opacity = material->getOpacity();
if(opacity <= 0.0f)
return;
// data
M_TYPES indicesType = subMesh->getIndicesType();
void * indices = subMesh->getIndices();
MVector2 * texCoords = subMesh->getTexCoords();
// begin / size
unsigned int begin = display->getBegin();
unsigned int size = display->getSize();
// get properties
M_PRIMITIVE_TYPES primitiveType = display->getPrimitiveType();
M_BLENDING_MODES blendMode = material->getBlendMode();
M_CULL_MODES cullMode = display->getCullMode();
MVector3 * diffuse = material->getDiffuse();
MVector3 * specular = material->getSpecular();
MVector3 * emit = material->getEmit();
float shininess = material->getShininess();
// get current fog color
MVector3 currentFogColor;
render->getFogColor(¤tFogColor);
// set cull mode
if(cullMode == M_CULL_NONE){
render->disableCullFace();
}
else{
render->enableCullFace();
render->setCullMode(cullMode);
}
// texture passes
unsigned int texturesPassNumber = MIN(8, material->getTexturesPassNumber());
// set blending mode
render->setBlendingMode(blendMode);
// alpha test
if(blendMode != M_BLENDING_ALPHA && texturesPassNumber > 0)
{
MTexturePass * texturePass = material->getTexturePass(0);
MTexture * texture = texturePass->getTexture();
if(texture)
{
if(texture->getTextureRef()->getComponents() > 3)
render->setAlphaTest(0.5f);
}
}
// set fog color depending on blending
switch(blendMode)
{
case M_BLENDING_ADD:
case M_BLENDING_LIGHT:
render->setFogColor(MVector3(0, 0, 0));
break;
case M_BLENDING_PRODUCT:
render->setFogColor(MVector3(1, 1, 1));
break;
}
// fixed pipeline
{
// no FX
render->bindFX(0);
// Vertex
render->enableVertexArray();
render->setVertexPointer(M_FLOAT, 3, vertices);
// Normal
if(normals)
{
render->enableNormalArray();
render->setNormalPointer(M_FLOAT, normals);
}
// Color
if(colors)
{
render->disableLighting();
render->enableColorArray();
render->setColorPointer(M_UBYTE, 4, colors);
//.........这里部分代码省略.........
示例9: exportFontBin
bool exportFontBin(const char * filename, MFont * font)
{
if(! font)
return false;
MEngine * engine = MEngine::getInstance();
MRenderingContext * render = engine->getRenderingContext();
// read image
MImage image;
render->bindTexture(font->getTextureId());
render->getTexImage(0, &image);
unsigned int width = image.getWidth();
unsigned int height = image.getHeight();
if(width == 0 && height == 0)
{
printf("Error : unable to create image font for %s\n", filename);
return false;
}
// create file
FILE * file = fopen(filename, "wb");
if(! file)
{
printf("Error : can't create file %s\n", filename);
return false;
}
// bin
fwrite(M_FONT_HEADER, sizeof(char), 8, file);
// version
int version = 1;
fwrite(&version, sizeof(int), 1, file);
// font size
unsigned int fontSize = font->getFontSize();
fwrite(&fontSize, sizeof(int), 1, file);
// write image
{
fwrite(&width, sizeof(int), 1, file);
fwrite(&height, sizeof(int), 1, file);
unsigned char color[4];
unsigned int x, y;
for(y=0; y<height; y++)
{
for(x=0; x<width; x++)
{
image.readPixel(x, y, color);
fwrite(&color[3], sizeof(char), 1, file);
}
}
}
// write characters infos
{
map <unsigned int, MCharacter> * characters = font->getCharacters();
// size
unsigned int size = font->getCharactersNumber();
fwrite(&size, sizeof(int), 1, file);
// characters
map <unsigned int, MCharacter>::iterator
mit (characters->begin()),
mend(characters->end());
for(;mit!=mend;++mit)
{
unsigned int charCode = mit->first;
MCharacter * character = &mit->second;
MVector2 pos = character->getPos();
MVector2 offset = character->getOffset();
MVector2 scale = character->getScale();
float xadvance = character->getXAdvance();
fwrite(&charCode, sizeof(int), 1, file);
fwrite(&pos, sizeof(float), 2, file);
fwrite(&offset, sizeof(float), 2, file);
fwrite(&scale, sizeof(float), 2, file);
fwrite(&xadvance, sizeof(float), 1, file);
}
}
fclose(file);
return true;
}
示例10: M_loadFont
//.........这里部分代码省略.........
continue;
// max y
max_y = MAX(max_y, slot->bitmap.rows);
if((pen_x + slot->bitmap.width + space) > width)
{
pen_x = space;
pen_y += max_y + space;
height += max_y + space;
max_y = 0;
}
// increment pen position
pen_x += slot->bitmap.width + space;
}
if(height == 0)
{
printf("ERROR Load Font : unable to create font texture\n");
FT_Done_FreeType(library);
delete [] file_base;
return false;
}
// create image
height = getNextPowerOfTwo(height);
image.create(M_UBYTE, width, height, 4);
memset(image.getData(), 0, image.getSize()*sizeof(char));
// init font
font->setTextureWidth(width);
font->setTextureHeight(height);
// create font texture
max_y = 0;
slot = face->glyph;
pen_x = space; pen_y = space;
for(n = 0; n<max_code; n++)
{
// load glyph image into the slot (erase previous one)
error = FT_Load_Char(face, n, FT_LOAD_RENDER | FT_LOAD_NO_HINTING);
if(error)
continue;
if(FT_Get_Char_Index(face, n) == 0)
continue;
// max y
max_y = MAX(max_y, slot->bitmap.rows);
if((pen_x + slot->bitmap.width + space) > (int)image.getWidth()){
pen_x = space;
pen_y += max_y + space;
}
// get character properties
float xAdvance = (slot->advance.x >> 6) / ((float)size);
MVector2 offset = MVector2((float)slot->bitmap_left - 1, - (float)slot->bitmap_top - 1) / ((float)size);
MVector2 pos = MVector2((float)(pen_x-1) / (float)width, (float)(pen_y-1) / (float)height);
MVector2 scale = MVector2((float)(slot->bitmap.width+2) / (float)width, (float)(slot->bitmap.rows+2) / (float)height);
// set character
font->setCharacter(n, MCharacter(xAdvance, offset, pos, scale));
// draw to image
drawBitmap(&image, &slot->bitmap, pen_x, pen_y);
// increment pen position
pen_x += slot->bitmap.width + space;
}
// send texture
MEngine * engine = MEngine().getInstance();
MRenderingContext * render = engine->getRenderingContext();
// gen texture id
unsigned int textureId = font->getTextureId();
if(textureId == 0)
{
render->createTexture(&textureId);
font->setTextureId(textureId);
}
// send texture image
render->bindTexture(textureId);
render->setTextureUWrapMode(M_WRAP_REPEAT);
render->setTextureVWrapMode(M_WRAP_REPEAT);
render->sendTextureImage(&image, 0, 1, 0);
// finish
FT_Done_FreeType(library);
delete [] file_base;
return true;
}
示例11: main
// main
int main(int argc, char **argv)
{
setlocale(LC_NUMERIC, "C");
// get engine (first time call onstructor)
MEngine * engine = MEngine::getInstance();
// get window (first time call onstructor)
MWindow * window = MWindow::getInstance();
// create window
window->create("Maratis", 1024,768, 32, false);
// set current directory
char rep[256];
getRepertory(rep, argv[0]);
window->setCurrentDirectory(rep);
// get Maratis (first time call onstructor)
Maratis * maratis = Maratis::getInstance();
MRenderingContext * render = engine->getRenderingContext();
// init gui
MGui * gui = MGui::getInstance();
gui->setRenderingContext(render);
gui->addFont(new MGuiTextureFont("font/default.tga"));
// init MaratisUI
window->setPointerEvent(MaratisUI::windowEvents);
// logo
{
MImage image;
if(! M_loadImage("gui/Title.png", &image))
return 0;
render->createTexture(&logoTextureId);
render->bindTexture(logoTextureId);
render->sendTextureImage(&image, false, false, false);
// clear window
draw();
MGuiText text("LOADING", MVector2(480, 280), 16, MVector4(1, 1, 1, 1));
text.draw();
window->swapBuffer();
}
// load project
if(argc > 1)
{
maratis->loadProject(argv[1]);
}
// time
unsigned int frequency = 60;
unsigned long previousFrame = 0;
unsigned long startTick = window->getSystemTick();
int f = 0;
int t = 0;
// on events
while(window->isActive())
{
// on events
if(window->onEvents())
{
// compute target tick
unsigned long currentTick = window->getSystemTick();
unsigned long tick = currentTick - startTick;
unsigned long frame = (unsigned long)(tick * (frequency * 0.001f));
// update elapsed time
unsigned int i;
unsigned int steps = (unsigned int)(frame - previousFrame);
if(window->getFocus())
{
// don't wait too much
if(steps >= (frequency/2))
{
update();
draw();
previousFrame += steps;
continue;
}
// update
for(i=0; i<steps; i++)
{
update();
previousFrame++;
t++;
if(t == frequency)
//.........这里部分代码省略.........
示例12: M_loadBinFont
bool M_loadBinFont(const char * filename, void * data)
{
// open file
FILE * file = fopen(filename, "rb");
if(! file)
{
printf("Error : can't read file %s\n", filename);
return false;
}
// bin
char header[8];
fread(header, sizeof(char), 8, file);
if(strcmp(header, "MFONT") != 0)
return false;
// version
int version;
fread(&version, sizeof(int), 1, file);
// font size
unsigned int fontSize;
fread(&fontSize, sizeof(int), 1, file);
// init font
MFont * font = (MFont *)data;
font->setFontSize(fontSize);
// create image
{
unsigned int width, height;
fread(&width, sizeof(int), 1, file);
fread(&height, sizeof(int), 1, file);
font->setTextureWidth(width);
font->setTextureHeight(height);
MImage image;
image.create(M_UBYTE, width, height, 4);
unsigned char color[4] = {255, 255, 255, 0};
unsigned int x, y;
for(y=0; y<height; y++)
{
for(x=0; x<width; x++)
{
fread(&color[3], sizeof(char), 1, file);
image.writePixel(x, y, color);
}
}
MEngine * engine = MEngine().getInstance();
MRenderingContext * render = engine->getRenderingContext();
// gen texture id
unsigned int textureId = font->getTextureId();
if(textureId == 0)
{
render->createTexture(&textureId);
font->setTextureId(textureId);
}
// send texture image
render->bindTexture(textureId);
render->setTextureUWrapMode(M_WRAP_REPEAT);
render->setTextureVWrapMode(M_WRAP_REPEAT);
render->sendTextureImage(&image, 0, 1, 0);
}
// read characters infos
{
// size
unsigned int size;
fread(&size, sizeof(int), 1, file);
// characters
unsigned int i;
for(i=0; i<size; i++)
{
unsigned int charCode;
MVector2 pos;
MVector2 offset;
MVector2 scale;
float xadvance;
fread(&charCode, sizeof(int), 1, file);
fread(&pos, sizeof(float), 2, file);
fread(&offset, sizeof(float), 2, file);
fread(&scale, sizeof(float), 2, file);
fread(&xadvance, sizeof(float), 1, file);
font->setCharacter(charCode, MCharacter(xadvance, offset, pos, scale));
}
}
fclose(file);
return true;
}