C++ (Cpp) glStencilFunc - 30 examples found. These are the top rated real world C++ (Cpp) examples of glStencilFunc extracted from open source projects.
Togglenavigation
HotExamplesENENRUDEFRESPTITJPZH
C++PHPC#JavaGoC++PythonJSTS
SearchC++(Cpp)glStencilFuncExamplesC++(Cpp)glStencilFunc-30examplesfound.ThesearethetopratedrealworldC++(Cpp)examplesofglStencilFuncextractedfromopensourceprojects.Youcanrateexamplestohelpusimprovethequalityofexamples.ProgrammingLanguage:C++(Cpp)Method/Function:glStencilFuncExamplesathotexamples.com:30Relatedget_envngx_conf_merge_valueuseRFLOAT_VALUEresultslAddHeadCThemeQStyleOptionatexitortp_initRelatedinlangsscriptReturn(PHP)Applications\PMTool\Models\Dao\Project_manager(PHP)ToxyNode(C#)ISymbolTable(C#)GetSwitch(Go)CheckErr(Go)MpInitiator(Java)AnalyzerWithCompilerReport(Java)Logging(Python)Stuff(Python)Example#10ShowfileFile:
PixelNode.cpp
Project:
dgkae/huntersvoidPixelNode::onDraw(constcocos2d::Mat4&transform,uint32_tflags)
{
autoglProgram=_programState->getGLProgram();
glProgram->use();
autoloc=glProgram->getUniformLocation("u_cbf_opacity");
glProgram->setUniformLocationWith1f(loc,_opacityAsAlpha?getOpacity()/255.f:1.f);
loc=glProgram->getUniformLocation("u_posexpand");
glProgram->setUniformLocationWith1f(loc,_opacityAsPosExpand?_posexpand*(1.f-getOpacity()/255.f):0.f);
loc=glProgram->getUniformLocation("u_mixcolor");
glProgram->setUniformLocationWith4fv(loc,&(_mixColor.x),1);
loc=glProgram->getUniformLocation("u_y_cut");
glProgram->setUniformLocationWith1f(loc,_yCut);
glProgram->setUniformsForBuiltins(transform);
glBindBuffer(GL_ARRAY_BUFFER,_vbo);
if(Configuration::getInstance()->supportsShareableVAO())
{
GL::bindVAO(_vao);
}
else
{
//TODO
}
if(_blend){
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
}else{
glDisable(GL_BLEND);
}
glEnable(GL_CULL_FACE);
//shadowcover打开depthtest同时在fsh中对a为0的进行discard,以保证重合交叠处不会交叠而加深。
glEnable(GL_DEPTH_TEST);
glDepthMask(true);
if(_stencil){
glEnable(GL_STENCIL_TEST);
//Drawfloor
glStencilFunc(GL_ALWAYS,1,0xFF);//Setanystencilto1
glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
glStencilMask(0xFF);//Writetostencilbuffer
glDepthMask(GL_FALSE);//Don'twritetodepthbuffer
glClear(GL_STENCIL_BUFFER_BIT);//Clearstencilbuffer(0bydefault)
}
if(_stenciled){
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_EQUAL,1,0xFF);//Passtestifstencilvalueis1
glStencilMask(0x00);//Don'twriteanythingtostencilbuffer
glDepthMask(GL_TRUE);//Writetodepthbuffer
}
glDrawArrays(GL_TRIANGLES,0,_count);
if(Configuration::getInstance()->supportsShareableVAO())
{
GL::bindVAO(0);
}
glDisable(GL_STENCIL_TEST);
glBindBuffer(GL_ARRAY_BUFFER,0);
glDisable(GL_DEPTH_TEST);
glDepthMask(false);
glEnable(GL_BLEND);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_count);
CHECK_GL_ERROR_DEBUG();
}Example#20ShowfileFile:
LightingStage.cpp
Project:
uvbs/GameProject voidTestStage::onRender(floatdFrame)
{
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
glEnable(GL_STENCIL_TEST);
GameWindow&window=Global::getDrawEngine()->getWindow();
intw=window.getWidth();
inth=window.getHeight();
for(LightList::iteratoriter=lights.begin(),itEnd=lights.end();
iter!=itEnd;++iter)
{
Light&light=*iter;
#if1
glColorMask(false,false,false,false);
glStencilFunc(GL_ALWAYS,1,1);
glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
for(BlockList::iteratoriter=blocks.begin(),itEnd=blocks.end();
iter!=itEnd;++iter)
{
Block&block=*iter;
renderPolyShadow(light,block.pos,block.getVertices(),block.getVertexNum());
}
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
glStencilFunc(GL_EQUAL,0,1);
glColorMask(true,true,true,true);
#endif
glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ONE);
glUseProgram(program);
glUniform2f(loc_lightLocation,light.pos.x,light.pos.y);
glUniform3f(loc_lightColor,light.color.x,light.color.y,light.color.z);
glUniform3f(loc_lightAttenuation,0,1/5.0,0);
glBegin(GL_QUADS);
glVertex2i(0,0);
glVertex2i(w,0);
glVertex2i(w,h);
glVertex2i(0,h);
glEnd();
glUseProgram(0);
glDisable(GL_BLEND);
glClear(GL_STENCIL_BUFFER_BIT);
}
glDisable(GL_STENCIL_TEST);
GLGraphics2D&g=::Global::getDrawEngine()->getGLGraphics();
g.beginRender();
RenderUtility::setFont(g,FONT_S8);
FixString<256>str;
Vec2ipos=Vec2i(10,10);
g.drawText(pos,str.format("LightsNum=%u",lights.size()));
g.endRender();
}Example#30ShowfileFile:
test-stencil.c
Project:
prabindh/freedrenovoidtest_stencil(void)
{
GLintnumStencilBits;
GLuintstencilValues[NumTests]={
0x7,//Resultoftest0
0x0,//Resultoftest1
0x2,//Resultoftest2
0xff//Resultoftest3.Weneedtofillthisvalueinarun-time
};
inti;
RD_START("stencil","");
display=get_display();
/*getanappropriateEGLframebufferconfiguration*/
ECHK(eglChooseConfig(display,config_attribute_list,&config,1,&num_config));
DEBUG_MSG("num_config:%d",num_config);
/*createanEGLrenderingcontext*/
ECHK(context=eglCreateContext(display,config,EGL_NO_CONTEXT,context_attribute_list));
surface=make_window(display,config,400,240);
ECHK(eglQuerySurface(display,surface,EGL_WIDTH,&width));
ECHK(eglQuerySurface(display,surface,EGL_HEIGHT,&height));
DEBUG_MSG("Buffer:%dx%d",width,height);
/*connectthecontexttothesurface*/
ECHK(eglMakeCurrent(display,surface,surface,context));
program=get_program(vertex_shader_source,fragment_shader_source);
GCHK(glBindAttribLocation(program,0,"aPosition"));
link_program(program);
/*nowsetupouruniform.*/
GCHK(uniform_location=glGetUniformLocation(program,"uColor"));
GCHK(glClearColor(0.0,0.0,0.0,0.0));
GCHK(glClearStencil(0x1));
GCHK(glClearDepthf(0.75));
GCHK(glEnable(GL_DEPTH_TEST));
GCHK(glEnable(GL_STENCIL_TEST));
//Settheviewport
GCHK(glViewport(0,0,width,height));
//Clearthecolor,depth,andstencilbuffers.Atthis
//point,thestencilbufferwillbe0x1forallpixels
GCHK(glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT));
//Usetheprogramobject
GCHK(glUseProgram(program));
//Loadthevertexposition
GCHK(glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,vVertices));
GCHK(glEnableVertexAttribArray(0));
//Test0:
//
//Initializeupper-leftregion.Inthiscase,the
//stencil-buffervalueswillbereplacedbecausethe
//stenciltestfortherenderedpixelswillfailthe
//stenciltest,whichis
//
//refmaskstencilmask
//(0x7&0x3)(0x1&0x3)
//
//butwherethegeometryfailsthedepthtest.The
//stencilvaluesforthesepixelswillbe0x0.
//
GCHK(glStencilFunc(GL_GREATER,0x3,0x3));
GCHK(glStencilOp(GL_KEEP,GL_DECR,GL_KEEP));
GCHK(glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_BYTE,indices[1]));
//Test2:
//
//Initializethelower-leftregion.Herewe'llincrement
//(withsaturation)thestencilvaluewhereboththe
//stencilanddepthtestspass.Thestenciltestfor
//thesepixelswillbe
//
//refmaskstencilmask
//(0x1&0x3)==(0x1&0x3)
//
//Thestencilvaluesforthesepixelswillbe0x2.
//
GCHK(glStencilFunc(GL_EQUAL,0x1,0x3));
GCHK(glStencilOp(GL_KEEP,GL_INCR,GL_INCR));
GCHK(glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_BYTE,indices[2]));
//Test3:
//
//Finally,initializethelower-rightregion.We'llinvert
//thestencilvaluewherethestenciltestsfails.The
//stenciltestforthesepixelswillbe
//
//refmaskstencilmask
//(0x2&0x1)==(0x1&0x1)
//
//Thestencilvalueherewillbesetto~((2^s-1)&0x1),
//(withthe0x1beingfromthestencilclearvalue),
//where's'isthenumberofbitsinthestencilbuffer
//
GCHK(glStencilFunc(GL_EQUAL,0x2,0x1));
GCHK(glStencilOp(GL_INVERT,GL_KEEP,GL_KEEP));
GCHK(glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_BYTE,indices[3]));
//Sincewedon'tknowatcompiletimehowmanystencilbitsarepresent,
//we'llquery,andupdatethevaluecorrectvalueinthe
//stencilValuesarraysforthefourthtests.We'llusethisvalue
//laterinrendering.
GCHK(glGetIntegerv(GL_STENCIL_BITS,&numStencilBits));
stencilValues[3]=~(((1<then=steady_clock::now();
boolcolor_mask_b=rsx::method_registers.color_mask_b();
boolcolor_mask_g=rsx::method_registers.color_mask_g();
boolcolor_mask_r=rsx::method_registers.color_mask_r();
boolcolor_mask_a=rsx::method_registers.color_mask_a();
gl_state.color_mask(color_mask_r,color_mask_g,color_mask_b,color_mask_a);
gl_state.depth_mask(rsx::method_registers.depth_write_enabled());
gl_state.stencil_mask(rsx::method_registers.stencil_mask());
if(gl_state.enable(rsx::method_registers.depth_test_enabled(),GL_DEPTH_TEST))
{
gl_state.depth_func(comparison_op(rsx::method_registers.depth_func()));
floatrange_near=rsx::method_registers.clip_min();
floatrange_far=rsx::method_registers.clip_max();
if(g_cfg.video.strict_rendering_mode)
gl_state.depth_range(range_near,range_far);
else
{
//Workaroundtopreservedepthprecisionbutrespectzdirection
//NinoKunisetsaveryrestrictedzrange(0.9x-1.)anddepthreads/testsarebroken
if(range_near<=range_far)
gl_state.depth_range(0.f,1.f);
else
gl_state.depth_range(1.f,0.f);
}
}
if(glDepthBoundsEXT&&(gl_state.enable(rsx::method_registers.depth_bounds_test_enabled(),GL_DEPTH_BOUNDS_TEST_EXT)))
{
gl_state.depth_bounds(rsx::method_registers.depth_bounds_min(),rsx::method_registers.depth_bounds_max());
}
gl_state.enable(rsx::method_registers.dither_enabled(),GL_DITHER);
if(gl_state.enable(rsx::method_registers.blend_enabled(),GL_BLEND))
{
glBlendFuncSeparate(blend_factor(rsx::method_registers.blend_func_sfactor_rgb()),
blend_factor(rsx::method_registers.blend_func_dfactor_rgb()),
blend_factor(rsx::method_registers.blend_func_sfactor_a()),
blend_factor(rsx::method_registers.blend_func_dfactor_a()));
autoblend_colors=rsx::get_constant_blend_colors();
glBlendColor(blend_colors[0],blend_colors[1],blend_colors[2],blend_colors[3]);
glBlendEquationSeparate(blend_equation(rsx::method_registers.blend_equation_rgb()),
blend_equation(rsx::method_registers.blend_equation_a()));
}
if(gl_state.enable(rsx::method_registers.stencil_test_enabled(),GL_STENCIL_TEST))
{
glStencilFunc(comparison_op(rsx::method_registers.stencil_func()),
rsx::method_registers.stencil_func_ref(),
rsx::method_registers.stencil_func_mask());
glStencilOp(stencil_op(rsx::method_registers.stencil_op_fail()),stencil_op(rsx::method_registers.stencil_op_zfail()),
stencil_op(rsx::method_registers.stencil_op_zpass()));
if(rsx::method_registers.two_sided_stencil_test_enabled())
{
glStencilMaskSeparate(GL_BACK,rsx::method_registers.back_stencil_mask());
glStencilFuncSeparate(GL_BACK,comparison_op(rsx::method_registers.back_stencil_func()),
rsx::method_registers.back_stencil_func_ref(),rsx::method_registers.back_stencil_func_mask());
glStencilOpSeparate(GL_BACK,stencil_op(rsx::method_registers.back_stencil_op_fail()),
stencil_op(rsx::method_registers.back_stencil_op_zfail()),stencil_op(rsx::method_registers.back_stencil_op_zpass()));
}
}
gl_state.enablei(rsx::method_registers.blend_enabled_surface_1(),GL_BLEND,1);
gl_state.enablei(rsx::method_registers.blend_enabled_surface_2(),GL_BLEND,2);
gl_state.enablei(rsx::method_registers.blend_enabled_surface_3(),GL_BLEND,3);
if(gl_state.enable(rsx::method_registers.logic_op_enabled(),GL_COLOR_LOGIC_OP))
{
gl_state.logic_op(logic_op(rsx::method_registers.logic_operation()));
}
gl_state.line_width(rsx::method_registers.line_width());
gl_state.enable(rsx::method_registers.line_smooth_enabled(),GL_LINE_SMOOTH);
gl_state.enable(rsx::method_registers.poly_offset_point_enabled(),GL_POLYGON_OFFSET_POINT);
gl_state.enable(rsx::method_registers.poly_offset_line_enabled(),GL_POLYGON_OFFSET_LINE);
gl_state.enable(rsx::method_registers.poly_offset_fill_enabled(),GL_POLYGON_OFFSET_FILL);
gl_state.polygon_offset(rsx::method_registers.poly_offset_scale(),rsx::method_registers.poly_offset_bias());
if(gl_state.enable(rsx::method_registers.cull_face_enabled(),GL_CULL_FACE))
{
gl_state.cull_face(cull_face(rsx::method_registers.cull_face_mode()));
}
gl_state.front_face(front_face(rsx::method_registers.front_face_mode()));
//TODO
//NV4097_SET_ANISO_SPREAD
//NV4097_SET_SPECULAR_ENABLE
//NV4097_SET_TWO_SIDE_LIGHT_EN
//NV4097_SET_FLAT_SHADE_OP
//NV4097_SET_EDGE_FLAG
//NV4097_SET_COLOR_KEY_COLOR
//NV4097_SET_SHADER_CONTROL
//NV4097_SET_ZMIN_MAX_CONTROL
//NV4097_SET_ANTI_ALIASING_CONTROL
//NV4097_SET_CLIP_ID_TEST_ENABLE
std::chrono::time_pointnow=steady_clock::now();
m_begin_time+=(u32)std::chrono::duration_cast<:chrono::microseconds>(now-then).count();
}Example#50ShowfileFile:
SceneObject_Decal.cpp
Project:
222464/EvolvedVirtualCreaturesRepo//InheritedfromBatchRenderer
voidSceneObject_Decal_BatchRenderer::Execute()
{
if(!GetScene()->m_renderingDeferred)
return;
glEnable(GL_STENCIL_TEST);
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
glDepthFunc(GL_LEQUAL);
glDepthMask(false);
glEnable(GL_POLYGON_OFFSET_FILL);
for(unsignedinti=0,numDecals=m_pDecals.size();iRender_Batch_NoTexture();
}
glColorMask(true,true,true,true);
//Stenciltest
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
glPolygonOffset(-2.0f,-2.0f);
//Re-render,secondpass
i=firstDecalInBatchIndex;
GetScene()->RebindGBufferRenderShader();
for(unsignedintj=0;j<8&&iRender_Batch_Textured();
}
glClear(GL_STENCIL_BUFFER_BIT);
}
GetScene()->SetCurrentGBufferRenderShader(Scene::e_plain);
glDisable(GL_POLYGON_OFFSET_FILL);
glDepthMask(true);
glDepthFunc(GL_LESS);
glDisable(GL_STENCIL_TEST);
}Example#60ShowfileFile:
qsgrenderer.cpp
Project:
SamuelNevala/qtdeclarativeQSGRenderer::ClipTypeQSGRenderer::updateStencilClip(constQSGClipNode*clip)
{
if(!clip){
glDisable(GL_STENCIL_TEST);
glDisable(GL_SCISSOR_TEST);
returnNoClip;
}
ClipTypeclipType=NoClip;
glDisable(GL_SCISSOR_TEST);
m_current_stencil_value=0;
m_current_scissor_rect=QRect();
while(clip){
QMatrix4x4m=m_current_projection_matrix;
if(clip->matrix())
m*=*clip->matrix();
//TODO:Checkformultisamplingandpixelgridalignment.
boolisRectangleWithNoPerspective=clip->isRectangular()
&&qFuzzyIsNull(m(3,0))&&qFuzzyIsNull(m(3,1));
boolnoRotate=qFuzzyIsNull(m(0,1))&&qFuzzyIsNull(m(1,0));
boolisRotate90=qFuzzyIsNull(m(0,0))&&qFuzzyIsNull(m(1,1));
if(isRectangleWithNoPerspective&&(noRotate||isRotate90)){
QRectFbbox=clip->clipRect();
qrealinvW=1/m(3,3);
qrealfx1,fy1,fx2,fy2;
if(noRotate){
fx1=(bbox.left()*m(0,0)+m(0,3))*invW;
fy1=(bbox.bottom()*m(1,1)+m(1,3))*invW;
fx2=(bbox.right()*m(0,0)+m(0,3))*invW;
fy2=(bbox.top()*m(1,1)+m(1,3))*invW;
}else{
Q_ASSERT(isRotate90);
fx1=(bbox.bottom()*m(0,1)+m(0,3))*invW;
fy1=(bbox.left()*m(1,0)+m(1,3))*invW;
fx2=(bbox.top()*m(0,1)+m(0,3))*invW;
fy2=(bbox.right()*m(1,0)+m(1,3))*invW;
}
if(fx1>fx2)
qSwap(fx1,fx2);
if(fy1>fy2)
qSwap(fy1,fy2);
GLintix1=qRound((fx1+1)*m_device_rect.width()*qreal(0.5));
GLintiy1=qRound((fy1+1)*m_device_rect.height()*qreal(0.5));
GLintix2=qRound((fx2+1)*m_device_rect.width()*qreal(0.5));
GLintiy2=qRound((fy2+1)*m_device_rect.height()*qreal(0.5));
if(!(clipType&ScissorClip)){
m_current_scissor_rect=QRect(ix1,iy1,ix2-ix1,iy2-iy1);
glEnable(GL_SCISSOR_TEST);
clipType|=ScissorClip;
}else{
m_current_scissor_rect&=QRect(ix1,iy1,ix2-ix1,iy2-iy1);
}
glScissor(m_current_scissor_rect.x(),m_current_scissor_rect.y(),
m_current_scissor_rect.width(),m_current_scissor_rect.height());
}else{
if(!(clipType&StencilClip)){
if(!m_clip_program.isLinked()){
m_clip_program.addShaderFromSourceCode(QOpenGLShader::Vertex,
"attributehighpvec4vCoord;\n"
"uniformhighpmat4matrix;\n"
"voidmain(){\n"
"gl_Position=matrix*vCoord;\n"
"}");
m_clip_program.addShaderFromSourceCode(QOpenGLShader::Fragment,
"voidmain(){\n"
"gl_FragColor=vec4(0.81,0.83,0.12,1.0);\n"//Trolltechgreenftw!
"}");
m_clip_program.bindAttributeLocation("vCoord",0);
m_clip_program.link();
m_clip_matrix_id=m_clip_program.uniformLocation("matrix");
}
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
glEnable(GL_STENCIL_TEST);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
glDepthMask(GL_FALSE);
if(m_vertex_buffer_bound){
glBindBuffer(GL_ARRAY_BUFFER,0);
m_vertex_buffer_bound=false;
}
if(m_index_buffer_bound){
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
m_index_buffer_bound=false;
}
m_clip_program.bind();
m_clip_program.enableAttributeArray(0);
clipType|=StencilClip;
}
glStencilFunc(GL_EQUAL,m_current_stencil_value,0xff);//stenciltest,ref,testmask
glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);//stencilfail,zfail,zpass
constQSGGeometry*g=clip->geometry();
Q_ASSERT(g->attributeCount()>0);
constQSGGeometry::Attribute*a=g->attributes();
glVertexAttribPointer(0,a->tupleSize,a->type,GL_FALSE,g->sizeOfVertex(),g->vertexData());
m_clip_program.setUniformValue(m_clip_matrix_id,m);
if(g->indexCount()){
glDrawElements(g->drawingMode(),g->indexCount(),g->indexType(),g->indexData());
}else{
glDrawArrays(g->drawingMode(),0,g->vertexCount());
}
++m_current_stencil_value;
}
clip=clip->clipList();
}
if(clipType&StencilClip){
m_clip_program.disableAttributeArray(0);
glStencilFunc(GL_EQUAL,m_current_stencil_value,0xff);//stenciltest,ref,testmask
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);//stencilfail,zfail,zpass
bindable()->reactivate();
}else{
glDisable(GL_STENCIL_TEST);
}
returnclipType;
}Example#70ShowfileFile:
text_widget.cpp
Project:
EQ4/genesisvoidTextWidget::draw(constglm::mat4&projection){
boolshould_hover=(_hover_on&&_hovering);
if(_background_on||should_hover){
glm::mat4bg_mvp=projection*_bg_model;
glm::vec4color=should_hover?_hover_color:_background_color;
gui_window->fill_rect(color,bg_mvp);
}
if(_icon_img){
glm::mat4icon_mvp=projection*_icon_model;
gui->draw_image(gui_window,_icon_img,icon_mvp);
}
glm::mat4label_mvp=projection*_label_model;
if(_text_interaction_on){
if(_placeholder_label.text().length()>0&&_label.text().length()==0)
_placeholder_label.draw(label_mvp,_placeholder_color);
}
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS,1,0xFF);
glStencilOp(GL_KEEP,GL_REPLACE,GL_REPLACE);
glStencilMask(0xFF);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
glClear(GL_STENCIL_BUFFER_BIT);
gui_window->fill_rect(glm::vec4(1.0f,1.0f,1.0f,1.0f),
left+label_start_x(),top+label_start_y(),
label_area_width(),_label.height());
glStencilFunc(GL_EQUAL,1,0xFF);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
_label.draw(label_mvp,_text_color);
glStencilFunc(GL_ALWAYS,1,0xFF);
glStencilOp(GL_KEEP,GL_REPLACE,GL_REPLACE);
glStencilMask(0xFF);
glClear(GL_STENCIL_BUFFER_BIT);
if(_text_interaction_on&&_have_focus&&_cursor_start!=-1&&_cursor_end!=-1){
if(_cursor_start==_cursor_end){
//drawcursor
glm::mat4cursor_mvp=projection*_cursor_model;
gui_window->fill_rect(_selection_color,cursor_mvp);
}else{
//drawselectionrectangle
glm::mat4sel_mvp=projection*_sel_model;
gui_window->fill_rect(_selection_color,sel_mvp);
glStencilFunc(GL_EQUAL,1,0xFF);
glStencilMask(0x00);
_label.draw(label_mvp,_sel_text_color);
}
}
glDisable(GL_STENCIL_TEST);
}Example#80ShowfileFile:
gl.cpp
Project:
dschaefer/swt-openglM(void,glStencilFunc,jintfunc,jintref,jintmask){
glStencilFunc(func,ref,mask);
}Example#90ShowfileFile:
matrix.c
Project:
akihiko-fujii/opengl-learning-experiencevoiddisplay(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
glViewport(0,0,glwidth,glheight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(1.5,(double)glwidth/(double)glheight,1.0,1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(150.0,100.0,-200.0,
0.0,0.0,0.0,
0.0,1.0,0.0);
glMultMatrixd(Rotate);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,gold_diff);
glPushMatrix();
glTranslated(sin(t),cos(t),-3.);
glRotatef(90,1.0f,0.0f,0.0f);
glutSolidSphere(.3,20,20);
glPopMatrix();
glutSolidSphere(1.5,20,20);
glLightfv(GL_LIGHT0,GL_POSITION,light0_pos);
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,red_light);
if(!colormask_on){
glColorMask(0,0,0,0);
glDepthMask(0);
}
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_STENCIL_TEST);
glStencilMask(~0);
if(frontcull){
glCullFace(GL_FRONT);
glStencilFunc(GL_ALWAYS,1,~0);
glStencilOp(GL_REPLACE,GL_KEEP,GL_REPLACE);
/*glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);*/
/*glStencilOp(GL_KEEP,GL_INCR,GL_KEEP);*/
glPushMatrix();
glTranslated(sin(t),cos(t),-3);
glRotatef(90,1.0f,0.0f,0.0f);
/*glRotatef(90,0.0f,0.0f,1.0f);*/
cylinder(.3,100,20);
glPopMatrix();
}
if(backcull){
glCullFace(GL_BACK);
glStencilFunc(GL_ALWAYS,1,~0);
glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);
/*glStencilOp(GL_KEEP,GL_DECR,GL_KEEP);*/
glPushMatrix();
glTranslated(sin(t),cos(t),-3.);
glRotatef(90,1.0f,0.0f,0.0f);
/*glRotatef(90,0.0f,0.0f,1.0f);*/
cylinder(.3,100,20);
glPopMatrix();
}
glDisable(GL_CULL_FACE);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
glDepthMask(GL_TRUE);
glStencilFunc(GL_EQUAL,1,~0);
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
glDisable(GL_DEPTH_TEST);
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,black_light);
glBegin(GL_QUADS);
glVertex2i(-10,-10);
glVertex2i(-10,10);
glVertex2i(10,10);
glVertex2i(10,-10);
glEnd();
glEnable(GL_DEPTH_TEST);
/*glEnable(GL_DEPTH_TEST);*/
glDisable(GL_STENCIL_TEST);
console();
t+=1e-2;
glFinish();
glutSwapBuffers();
}Example#100ShowfileFile:
MapRenderer.cpp
Project:
LeonardKoenig/openrwvoidMapRenderer::draw(GameWorld*world,constMapInfo&mi)
{
renderer->pushDebugGroup("Map");
renderer->useProgram(rectProg);
//Worldoutthenumberofunitspertile
glm::vec2worldSize(GAME_MAP_SIZE);
constintmapBlockLine=8;
glm::vec2tileSize=worldSize/(float)mapBlockLine;
//Determinethescaletoshowtherightnumberofworldunitsonthescreen
floatworldScale=mi.screenSize/mi.worldSize;
autoproj=renderer->get2DProjection();
glm::mat4view,model;
renderer->setUniform(rectProg,"proj",proj);
renderer->setUniform(rectProg,"model",glm::mat4());
renderer->setUniform(rectProg,"colour",glm::vec4(0.f,0.f,0.f,1.f));
view=glm::translate(view,glm::vec3(mi.screenPosition,0.f));
if(mi.clipToSize)
{
glBindVertexArray(circle.getVAOName());
glBindTexture(GL_TEXTURE_2D,0);
glm::mat4circleView=glm::scale(view,glm::vec3(mi.screenSize));
renderer->setUniform(rectProg,"view",circleView);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS,1,0xFF);
glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
glStencilMask(0xFF);
glColorMask(0x00,0x00,0x00,0x00);
glDrawArrays(GL_TRIANGLE_FAN,0,182);
glColorMask(0xFF,0xFF,0xFF,0xFF);
glStencilFunc(GL_EQUAL,1,0xFF);
}
view=glm::scale(view,glm::vec3(worldScale));
view=glm::rotate(view,mi.rotation,glm::vec3(0.f,0.f,1.f));
view=glm::translate(view,glm::vec3(glm::vec2(-1.f,1.f)*mi.worldCenter,0.f));
renderer->setUniform(rectProg,"view",view);
glBindVertexArray(rect.getVAOName());
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,0);
//radar00=-x,+y
//incrementinginX,thenY
intinitX=-(mapBlockLine/2);
intinitY=-(mapBlockLine/2);
for(intm=0;mdata->textures[{name,""}];
glBindTexture(GL_TEXTURE_2D,texture->getName());
intmX=initX+(m%mapBlockLine);
intmY=initY+(m/mapBlockLine);
autotc=glm::vec2(mX,mY)*tileSize+glm::vec2(tileSize/2.f);
glm::mat4tilemodel=model;
tilemodel=glm::translate(tilemodel,glm::vec3(tc,0.f));
tilemodel=glm::scale(tilemodel,glm::vec3(tileSize,1.f));
renderer->setUniform(rectProg,"model",tilemodel);
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
}
//Fromhereonoutwewillworkinscreenspace
renderer->setUniform(rectProg,"view",glm::mat4());
if(mi.clipToSize){
glDisable(GL_STENCIL_TEST);
//Weonlyneedtheouterringifwe'reclipping.
glBlendFuncSeparate(GL_DST_COLOR,GL_ZERO,GL_ONE,GL_ZERO);
TextureData::HandleradarDisc=data->findTexture("radardisc");
glm::mat4model;
model=glm::translate(model,glm::vec3(mi.screenPosition,0.0f));
model=glm::scale(model,glm::vec3(mi.screenSize*1.07));
renderer->setUniform(rectProg,"model",model);
glBindTexture(GL_TEXTURE_2D,radarDisc->getName());
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
glBlendFuncSeparate(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ZERO);
}
for(auto&blip:world->state->radarBlips)
{
glm::vec2blippos(blip.second.coord);
if(blip.second.target>0)
{
GameObject*object=nullptr;
switch(blip.second.type){
caseBlipData::Vehicle:
object=world->vehiclePool.find(blip.second.target);
break;
caseBlipData::Character:
object=world->pedestrianPool.find(blip.second.target);
break;
caseBlipData::Pickup:
object=world->pickupPool.find(blip.second.target);
break;
default:break;
}
if(object)
{
blippos=glm::vec2(object->getPosition());
}
}
drawBlip(blippos,view,mi,blip.second.texture);
}
//Drawtheplayerblip
autoplayer=world->pedestrianPool.find(world->state->playerObject);
if(player)
{
glm::vec2plyblip(player->getPosition());
floathdg=glm::roll(player->getRotation());
drawBlip(plyblip,view,mi,"radar_centre",mi.rotation-hdg);
}
drawBlip(mi.worldCenter+glm::vec2(0.f,mi.worldSize),view,mi,"radar_north",0.f,24.f);
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D,0);
glUseProgram(0);
///@TODOmigratetousingtherenderer
renderer->invalidate();
renderer->popDebugGroup();
}Example#110ShowfileFile:
commander.c
Project:
davebiffuk/commanderstaticvoidnew_ship(ModeInfo*mi)
{
commander_conf*cp=&commander[MI_SCREEN(mi)];
inti;
GLfloat*this_v;
GLint*p;
/*GLfloat*this_n;*/
intcount;
#if0
intwire=MI_IS_WIREFRAME(mi);
GLfloatbcolor[4]={0.2,0.2,0.2,0.2};
GLfloatbspec[4]={0.1,0.1,0.1,0.1};
GLfloatbshiny=32.0;
GLfloatpos[4]={-8.0,-8.0,-16.0,0.0};/*-6-6-16*/
GLfloatamb[4]={0.2,0.2,0.2,0.4};
GLfloatdif[4]={0.2,0.2,0.2,0.2};
GLfloatspc[4]={0.0,0.0,0.0,0.0};
if(!wire){
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0,GL_POSITION,pos);
glLightfv(GL_LIGHT0,GL_AMBIENT,amb);
glLightfv(GL_LIGHT0,GL_DIFFUSE,dif);
glLightfv(GL_LIGHT0,GL_SPECULAR,spc);
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,bcolor);
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,bspec);
glMateriali(GL_FRONT_AND_BACK,GL_SHININESS,bshiny);
}
#endif
cp->list=glGenLists(1);
glNewList(cp->list,GL_COMPILE);
if(MI_IS_MONO(mi)){
/*FIXMEsupportmonodisplay*/
abort();
}
/*wireframestrategy:usestencilbuffer,notpolygonoffset,
*becauseit'simpossibletogettherightparametersfor
*glPolygonOffset()reliably*/
/*hidden-lineremovalasper
*http://glprogramming.com/red/chapter14.html#name16
*/
/*TODO:
-reinstatechoiceofwireframevsfilled
-rationalisesomeoftheduplicatedcodebelow
*/
glEnable(GL_STENCIL_TEST);
glEnable(GL_DEPTH_TEST);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_ALWAYS,0,1);
glStencilOp(GL_INVERT,GL_INVERT,GL_INVERT);
glColor3f(1.0,1.0,1.0);
p=ship_f[cp->which];
this_v=ship_v[cp->which];
/*fordebugging-drawaxes*/
#if0
glLineWidth(1);
glBegin(GL_LINES);glVertex3f(0,0,0);glVertex3f(10,0,0);glEnd();
glBegin(GL_LINES);glVertex3f(0,0,0);glVertex3f(0,10,0);glEnd();
glBegin(GL_LINES);glVertex3f(0.1,0,0);glVertex3f(0.1,10,0);glEnd();
glBegin(GL_LINES);glVertex3f(0,0,0);glVertex3f(0,0,10);glEnd();
glBegin(GL_LINES);glVertex3f(0,0.1,0);glVertex3f(0,0.1,10);glEnd();
glBegin(GL_LINES);glVertex3f(0,0.2,0);glVertex3f(0,0.2,10);glEnd();
#endif
/*drawthewireframeshape*/
while(*p!=0){
count=*p;p++;
/*drawoutlinepolygon*/
if(count==1){glBegin(GL_POINTS);}
elseif(count==2){
/*chunkylines:-)*/
glLineWidth(2);
glBegin(GL_LINES);
}
else{
glLineWidth(2);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glBegin(GL_POLYGON);
do_normal(this_v[p[0]*3],this_v[p[0]*3+1],this_v[p[0]*3+2],
this_v[p[1]*3],this_v[p[1]*3+1],this_v[p[1]*3+2],
this_v[p[2]*3],this_v[p[2]*3+1],this_v[p[2]*3+2]);
}
for(i=0;i=3){
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glBegin(GL_POLYGON);
do_normal(this_v[p[0]*3],this_v[p[0]*3+1],this_v[p[0]*3+2],
this_v[p[1]*3],this_v[p[1]*3+1],this_v[p[1]*3+2],
this_v[p[2]*3],this_v[p[2]*3+1],this_v[p[2]*3+2]);
for(i=0;inpoints++;
p+=count;
}
glEndList();
}Example#120ShowfileFile:
ClippingNodeTest.cpp
Project:
AppleJDay/cocos2d-xvoidRawStencilBufferTest::setupStencilForDrawingOnPlane(GLintplane)
{
GLintplaneMask=0x1<m_nPaintWidth);
drawHeight=min(m_nWindowHeight,m_pDoc->m_nPaintHeight);
intstartrow=m_pDoc->m_nPaintHeight-(scrollpos.y+drawHeight);
if(startrow<0)startrow=0;
m_pPaintBitstart=m_pDoc->m_ucPainting+3*((m_pDoc->m_nPaintWidth*startrow)+scrollpos.x);
m_nDrawWidth=drawWidth;
m_nDrawHeight=drawHeight;
m_nStartRow=startrow;
m_nEndRow=startrow+drawHeight;
m_nStartCol=scrollpos.x;
m_nEndCol=m_nStartCol+drawWidth;
//Implementedgeclippinghereusingstencilbuffer
//Therearetwosteps:
//1.Initializestencilbufferbysettingcolorbuffermaskstofalse
//andthensettingappropriaterefvaluetostencilbufferbyfailing
//thestenciltesteverytime.
//2.Usetheinitializedstencilbufferandstenciltesttowriteonly
//inthelocationswherestencilvalueis1
if(!valid()){
//Quickexplanation:
//Stencilbuffergivesanoptiontowhich
//fragmentsshouldbedrawnandwhichshouldn't
//moreinfo:https://en.wikipedia.org/wiki/Stencil_buffer
/**************Step1**************/
glEnable(GL_STENCIL_TEST);
/*BasicallyglStencilMaskallowsustosetabitmaskthatis
ANDedwiththestencilvalueabouttobewrittentothebuffer*/
/*----------------------------------------------------------------*/
//0xFFmeanswesetallstencilvaluesto1perbit,nomask
glStencilMask(0xFF);
//clearstencilbufferwitih0s
glClear(GL_STENCIL_BUFFER_BIT);
/*ConfigureStencilTesting*/
/*a.glStencilFuncdescribeswhatOpenGLshoulddo
withthecontentofthestencilbuffer
/*b.glStencilOpdescribeshowwecanupdate
thestencilbuffer
/*------------------------------------------------*/
//Forcedrawingtostencilbydeclaringstenciltestfunctionfails
//Thismeanswedraw1sontestfail(always)
glStencilFunc(GL_NEVER,1,0xFF);
//replacestencilbuffervaluestoref=1,2ndparameterofglStencilFunc
glStencilOp(GL_REPLACE,GL_KEEP,GL_KEEP);
//Disableallcolorchannelssostencilbufferwon'taffect
//thecontentofthecolorbuffer
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
//Drawstencilshape
glBegin(GL_TRIANGLE_STRIP);
//Gettheverticesforthepaintview
glVertex2f(0,m_nWindowHeight-m_nDrawHeight);//bottomleft
glVertex2f(m_nDrawWidth,m_nWindowHeight-m_nDrawHeight);//bottomright
glVertex2f(0,m_nWindowHeight);//topleft
glVertex2f(m_nDrawWidth,m_nWindowHeight);//topright
glEnd();
/**************Step2**************/
//Enablecolor
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
//nomoremodifyingofstencilbufferonstencil
glStencilMask(0);
//stenciltest:onlypassstenciltestatstencilValuelessthan0
//andwriteactualcontenttocolorbufferonlyatstencilshapelocations.
glStencilFunc(GL_LESS,0,0xFF);
}
}Example#180ShowfileFile:
RenderTextureTest.cpp
Project:
SPUDevelopers/NaturalizevoidRenderTextureTestDepthStencil::onBeforDraw()
{
glStencilFunc(GL_NOTEQUAL,1,0xFF);
}Example#190ShowfileFile:
caGlPort_Renderer.cpp
Project:
kaikai2/curvedanivoidglRenderer::render(constiClipState&rClipState)
{
glClipStateresult;
result.reset(&rClipState);
floatalpha=result.alpha;
constPoint3f&color=result.color;
constRect&clip=result.clip;
if(clip.GetWidth()&&clip.GetHeight())
{
glColorMask(0,0,0,0); //SetColorMask
glEnable(GL_STENCIL_TEST); //EnableStencilBufferFor"marking"TheFloor
glStencilFunc(GL_ALWAYS,1,1); //AlwaysPasses,1BitPlane,1AsMask
glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE); //WeSetTheStencilBufferTo1WhereWeDrawAnyPolygon
//KeepIfTestFails,KeepIfTestPassesButBufferTestFails
//ReplaceIfTestPasses
glDisable(GL_DEPTH_TEST); //DisableDepthTesting
//DrawFloor(); //DrawTheFloor(DrawsToTheStencilBuffer)
glBegin(GL_QUADS);
glVertex3f(result.position.x+clip.leftTop.x,result.position.y+clip.leftTop.y,0);
glVertex3f(result.position.x+clip.rightBottom.x,result.position.y+clip.leftTop.y,0);
glVertex3f(result.position.x+clip.rightBottom.x,result.position.y+clip.rightBottom.y,0);
glVertex3f(result.position.x+clip.leftTop.x,result.position.y+clip.rightBottom.y,0);
glEnd();
//WeOnlyWantToMarkItInTheStencilBuffer
//glEnable(GL_DEPTH_TEST); //EnableDepthTesting
glColorMask(1,1,1,1); //SetColorMasktoTRUE,TRUE,TRUE,TRUE
glStencilFunc(GL_EQUAL,1,1); //WeDrawOnlyWhereTheStencilIs1
//(I.E.WhereTheFloorWasDrawn)
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP); //Don'tChangeTheStencilBuffer
}
glColor4f(color.x,color.y,color.z,alpha);
constImage&image=result.image;
if(image.valid())
{
Wm4::Matrix3fm33;
result.getMatrix(m33,1,1,1,1);
//glClipState::updateMatrix(m33,(constglClipState&)rClipState,(constglClipState&)rParentClipState);
m33=m33.Transpose();
glTexture&glTex=*(glTexture*)&image.getTexture();
unsignedinttex=glTex.getGlTexture();
glBindTexture(GL_TEXTURE_2D,tex);
constRect&texRect=image.getRect();
constfloatw_2=texRect.GetWidth()*0.5f;
constfloath_2=texRect.GetHeight()*0.5f;
Wm4::Vector3fwmPosition0=m33*Wm4::Vector3f(-w_2,-h_2,1.f);
Wm4::Vector3fwmPosition1=m33*Wm4::Vector3f(w_2,-h_2,1.f);
Wm4::Vector3fwmPosition2=m33*Wm4::Vector3f(w_2,h_2,1.f);
Wm4::Vector3fwmPosition3=m33*Wm4::Vector3f(-w_2,h_2,1.f);
floatleft=(float)texRect.leftTop.x/glTex.getWidth();
floatright=(float)texRect.rightBottom.x/glTex.getWidth();
floattop=(float)texRect.leftTop.y/glTex.getHeight();
floatbottom=(float)texRect.rightBottom.y/glTex.getHeight();
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_QUADS);
glTexCoord2f(left,top);
glVertex3f(wmPosition0.X(),wmPosition0.Y(),0.5f);//x-,y-
glTexCoord2f(right,top);
glVertex3f(wmPosition1.X(),wmPosition1.Y(),0.5f);//x+,y-
glTexCoord2f(right,bottom);
glVertex3f(wmPosition2.X(),wmPosition2.Y(),0.5f);//x+,y+
glTexCoord2f(left,bottom);
glVertex3f(wmPosition3.X(),wmPosition3.Y(),0.5f);//x-,y+
glEnd();
}
conststd::string&text=result.text;
if(text.length())
{
glport::Font*pFont=fontmap->GetFont("Impact");
if(pFont)
{
glPushMatrix();
glTranslatef(result.position.x,result.position.y,0);
glScalef(result.scale.x,-result.scale.y,1);//reverseydireciton
glTranslatef(-result.anchorOffPos.x,-result.anchorOffPos.y,0);
glDisable(GL_TEXTURE_2D);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glLineWidth(0.3f);
pFont->textOut(text.c_str());
glPopMatrix();
}
}
glDisable(GL_STENCIL_TEST);
}Example#200ShowfileFile:
ogl.cpp
Project:
cdlewis/extremetuxracervoidset_gl_options(TRenderModemode)
{
switch(mode){
caseGUI:
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
glDisable(GL_NORMALIZE);
glDisable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glDisable(GL_STENCIL_TEST);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_COLOR_MATERIAL);
glDepthMask(GL_TRUE);
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LESS);
glDisable(GL_FOG);
break;
caseGAUGE_BARS:
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
glDisable(GL_NORMALIZE);
glDisable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glDisable(GL_STENCIL_TEST);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glDisable(GL_COLOR_MATERIAL);
glDepthMask(GL_TRUE);
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LESS);
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
break;
caseTEXFONT:
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
glDisable(GL_NORMALIZE);
glDisable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glDisable(GL_STENCIL_TEST);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_COLOR_MATERIAL);
glDepthMask(GL_TRUE);
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LESS);
break;
caseCOURSE:
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glDisable(GL_NORMALIZE);
glDisable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glDisable(GL_STENCIL_TEST);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_COLOR_MATERIAL);
glDepthMask(GL_TRUE);
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LEQUAL);
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
break;
caseTREES:
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glDisable(GL_NORMALIZE);
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glDisable(GL_STENCIL_TEST);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_COLOR_MATERIAL);
glDepthMask(GL_TRUE);
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LESS);
glAlphaFunc(GL_GEQUAL,0.5);
break;
casePARTICLES:
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
glDisable(GL_NORMALIZE);
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glDisable(GL_STENCIL_TEST);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_COLOR_MATERIAL);
glDepthMask(GL_TRUE);
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LESS);
glAlphaFunc(GL_GEQUAL,0.5);
break;
caseSKY:
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
glDisable(GL_NORMALIZE);
glDisable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glDisable(GL_STENCIL_TEST);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_COLOR_MATERIAL);
glDepthMask(GL_FALSE);
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LESS);
break;
caseFOG_PLANE:
glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
glDisable(GL_NORMALIZE);
glDisable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glDisable(GL_STENCIL_TEST);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_COLOR_MATERIAL);
glDepthMask(GL_TRUE);
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LESS);
break;
caseTUX:
glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_NORMALIZE);
glDisable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glDisable(GL_STENCIL_TEST);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_COLOR_MATERIAL);
glDepthMask(GL_TRUE);
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LESS);
break;
caseTUX_SHADOW:
#ifdefUSE_STENCIL_BUFFER
glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
glDisable(GL_NORMALIZE);
glDisable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glEnable(GL_STENCIL_TEST);
glDisable(GL_COLOR_MATERIAL);
glDepthMask(GL_FALSE);
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LESS);
glStencilFunc(GL_EQUAL,0,~0);
glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);
#else
glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
glDisable(GL_NORMALIZE);
glDisable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glDisable(GL_STENCIL_TEST);
glDisable(GL_COLOR_MATERIAL);
glDepthMask(GL_TRUE);
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LESS);
#endif
break;
caseTRACK_MARKS:
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glDisable(GL_NORMALIZE);
glDisable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glDisable(GL_STENCIL_TEST);
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDepthMask(GL_FALSE);
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LEQUAL);
break;
default:
Message("notavalidrendermode","");
}
}Example#210ShowfileFile:
e_shadow.c
Project:
madmann91/All-In-A-Mouse-s-Nightvoide_beginpass(e_device_t*device,unsignedintpass)
{
glPushAttrib(GL_ENABLE_BIT|GL_STENCIL_BUFFER_BIT|GL_POLYGON_BIT);
switch(pass)
{
caseE_RENDER_MESHES:
glBindProgramARB(GL_VERTEX_PROGRAM_ARB,e_programids[E_PROGRAM_PASSTOFRAGMENT]);
glEnable(GL_VERTEX_PROGRAM_ARB);
glEnable(GL_FRAGMENT_PROGRAM_ARB);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
break;
caseE_RENDER_SHADOWS:
//Thesupportofthisextensiondependsonthe3Dcard
if(glActiveStencilFaceEXT)
{
glActiveStencilFaceEXT(GL_BACK);
glStencilOp(GL_KEEP,GL_INCR_WRAP_EXT,GL_KEEP);
glActiveStencilFaceEXT(GL_FRONT);
glStencilOp(GL_KEEP,GL_DECR_WRAP_EXT,GL_KEEP);
glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);
}
else
glEnable(GL_CULL_FACE);
glBindProgramARB(GL_VERTEX_PROGRAM_ARB,e_programids[E_PROGRAM_SHADOW]);
glEnable(GL_VERTEX_PROGRAM_ARB);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
glDepthMask(GL_FALSE);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS,0,~0);
glEnable(GL_DEPTH_TEST);
break;
caseE_RENDER_SHADING:
glBindProgramARB(GL_VERTEX_PROGRAM_ARB,e_programids[E_PROGRAM_PASSTOFRAGMENT]);
glEnable(GL_VERTEX_PROGRAM_ARB);
glEnable(GL_FRAGMENT_PROGRAM_ARB);
glBlendFunc(GL_ONE,GL_ONE);
glEnable(GL_BLEND);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_EQUAL,0,~0);
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
glDepthFunc(GL_LEQUAL);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
break;
caseE_RENDER_OUTLINES:
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
#ifdefE_OUTLINES_SMOOTH
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
#endif
glLineWidth(E_OUTLINES_WIDTH);
glPolygonOffset(1.0f,1.0f);
glEnable(GL_POLYGON_OFFSET_LINE);
glColor3ub(0,0,0);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
glEnable(GL_DEPTH_TEST);
break;
}
}Example#220ShowfileFile:
gamegraphics.c
Project:
BackupTheBerlios/gltron-svnvoiddrawCam(Player*p,PlayerVisual*pV){
inti;
floatup[3]={0,0,1};
Visual*d=&pV->display;
floatreflectivity=getReflectivity();
//computeshadowcolorbasedonglocalconstant&reflectivity
for(i=0;i<4;i++)
gCurrentShadowColor[i]=gShadowColor[i]*(1-reflectivity);
glColor3f(0.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
doPerspective(gSettingsCache.fov,(float)d->vp_w/(float)d->vp_h,
gSettingsCache.znear,box2_Diameter(&game2->level->boundingBox)*6.5f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
doLookAt(p->camera->cam,p->camera->target,up);
glDisable(GL_LIGHTING);//initialconfigatframestart
glDisable(GL_BLEND);//initialconfigatframestart
//disablewritestoalpha
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_FALSE);
/*skybox*/
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
drawSkybox(box2_Diameter(&game2->level->boundingBox)*2.5f);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
/*skyboxdone*/
/*floor*/
if(reflectivity==0){
//drawfloortofbandstencil(setto1),
//usingalpha-blending
//TODO:drawflooralphatofb
video_Shader_Setup(&gWorld->floor_shader);
glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
glStencilFunc(GL_ALWAYS,1,255);
glEnable(GL_STENCIL_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
nebu_Mesh_DrawGeometry(gWorld->floor);
glDisable(GL_BLEND);
glDisable(GL_STENCIL_TEST);
video_Shader_Cleanup(&gWorld->floor_shader);
}else{
/*reflections*/
/*firstdrawreflectortostencil*/
/*andreflectoralphatofb*/
video_Shader_Setup(&gWorld->floor_shader);
//storeonlyreflectoralphainframebuffer
glDepthMask(GL_FALSE);
glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
glStencilFunc(GL_ALWAYS,1,255);
glEnable(GL_STENCIL_TEST);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_TRUE);
//glEnable(GL_ALPHA_TEST);
//glAlphaFunc(GL_GREATER,0.1f);
nebu_Mesh_DrawGeometry(gWorld->floor);
//glDisable(GL_ALPHA_TEST);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
glDepthMask(GL_TRUE);
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
glStencilFunc(GL_EQUAL,1,255);
video_Shader_Cleanup(&gWorld->floor_shader);
/*thendrawworld&skyboxreflected,wherestencilisset*/
/*protectthealphabuffer*/
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_FALSE);
isRenderingReflection=1;//hack:reverselighting
glPushMatrix();
glScalef(1,1,-1);
glCullFace(GL_FRONT);//reverseculling
//clipskybox&worldtofloorplane
glEnable(GL_CLIP_PLANE0);
{
doubleplane[]={0,0,1,0};
glClipPlane(GL_CLIP_PLANE0,plane);
}
drawSkybox(box2_Diameter(&game2->level->boundingBox)*2.5f);
drawWorld(p,pV);
glDisable(GL_CLIP_PLANE0);
glCullFace(GL_BACK);
glPopMatrix();
isRenderingReflection=0;//hack:normallighting
/*thenblendtheskyboxintothescene,wherestencilisset*/
/*modulatewiththedestinationalpha*/
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_DST_ALPHA,GL_DST_ALPHA);
drawSkybox(box2_Diameter(&game2->level->boundingBox)*2.5f);
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
/*thenblendreflectorintothescene*/
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1,1,1,1-reflectivity);
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
glStencilFunc(GL_ALWAYS,1,255);
video_Shader_Setup(&gWorld->floor_shader);
nebu_Mesh_DrawGeometry(gWorld->floor);
video_Shader_Cleanup(&gWorld->floor_shader);
glDisable(GL_STENCIL_TEST);
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
}
/*floordone*/
/*planarshadows*/
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
if(reflectivity!=1)//therearenoshadowsonperfectmirrors
drawPlanarShadows(p);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
/*planarshadowsdone*/
drawWorld(p,pV);
/*transparentstuff*/
/*drawtheglowaroundtheotherplayers:*/
if(gSettingsCache.show_glow==1){
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
for(i=0;iplayers;i++)
{
if(p!=game->player+i&&PLAYER_IS_ACTIVE(game->player+i))
{
drawGlow(p->camera,game->player+i,gPlayerVisuals+i,
d,TRAIL_HEIGHT*4);
}
}
glDisable(GL_BLEND);
}
}Example#230ShowfileFile:
DrawTerrainAbove.cpp
Project:
PhilColbert/LK8000//
//DrawthereachableSHADEDterrainglideamoeba
//Thisisnottheoutlinedperimeter
//
voidMapWindow::DrawTerrainAbove(LKSurface&Surface,constRECT&rc){
//Letstrytomakeitbetterunderstandablewithagoto.
//IfCARorGAusersdontwantamoeba,theyshoulddisableitinconfig.
//Otherwiseweshouldpaintit,nothideitautomatically!
//Herearetheconditionsweprintthisamoeba,otherwisewereturn;
//FirstisweareinSIMmodeandwechangedthealtitude;
if(SIMMODE&&DerivedDrawInfo.AltitudeAGL>100)goto_doit;
//Second,ifweareflying
if(DerivedDrawInfo.Flying)goto_doit;
return;
_doit:
#ifndefENABLE_OPENGL
LKColorwhitecolor=LKColor(0xff,0xff,0xff);
LKColorgraycolor=LKColor(0xf0,0xf0,0xf0);
LKColororigcolor=TempSurface.SetTextColor(whitecolor);
TempSurface.SetBackgroundTransparent();
TempSurface.SetBkColor(whitecolor);
TempSurface.SelectObject(LK_WHITE_PEN);
TempSurface.SetTextColor(graycolor);
TempSurface.SelectObject(hAboveTerrainBrush);
TempSurface.Rectangle(rc.left,rc.top,rc.right,rc.bottom);
TempSurface.SelectObject(LK_WHITE_PEN);
TempSurface.SelectObject(LKBrush_White);
TempSurface.Polygon(Groundline,NUMTERRAINSWEEPS+1);
//needtodothistopreventdrawingofcoloredoutline
TempSurface.SelectObject(LK_WHITE_PEN);
#ifdefHAVE_HATCHED_BRUSH
Surface.TransparentCopy(
rc.left,rc.top,
rc.right-rc.left,rc.bottom-rc.top,
TempSurface,
rc.left,rc.top);
#else
Surface.AlphaBlendNotWhite(rc,TempSurface,rc,255/2);
#endif
//restoreoriginalcolor
TempSurface.SetTextColor(origcolor);
TempSurface.SetBackgroundOpaque();
#else
Canvas&canvas=Surface;
constGLEnablestencil;
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
glDepthMask(GL_FALSE);
glStencilFunc(GL_NEVER,1,0xFF);
glStencilOp(GL_REPLACE,GL_KEEP,GL_KEEP);//draw1sontestfail(always)
//drawstencilpattern
glStencilMask(0xFF);
glClear(GL_STENCIL_BUFFER_BIT);//needsmask=0xFF
canvas.DrawPolygon(Groundline,NUMTERRAINSWEEPS+1);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
glDepthMask(GL_TRUE);
glStencilMask(0x00);
//drawwherestencil'svalueis0
glStencilFunc(GL_EQUAL,0,0xFF);
canvas.DrawFilledRectangle(rc.left,rc.top,rc.right,rc.bottom,AboveTerrainColor);
#endif
}Example#240ShowfileFile:
CCClippingNode.cpp
Project:
smj10j/LightSwarmvoidClippingNode::onBeforeVisit()
{
///////////////////////////////////
//INIT
//incrementthecurrentlayer
s_layer++;
//maskofthecurrentlayer(ie:forlayer3:00000100)
GLintmask_layer=0x1<::iteratoriter=mDrawFace.begin();
iter!=mDrawFace.end();iter++)
{
LLFace*facep=*iter;
facep->mDistance=-facep->mCenterLocal.mV[2];
}
std::sort(mDrawFace.begin(),mDrawFace.end(),LLFace::CompareDistanceGreater());
staticconstLLCachedControlrender_transparent_water("RenderTransparentWater",false);
if(!render_transparent_water)
{
//renderwaterforlowendhardware
renderOpaqueLegacyWater();
return;
}
LLGLEnableblend(GL_BLEND);
if((mVertexShaderLevel>0)&&!sSkipScreenCopy)
{
shade();
return;
}
LLVOSky*voskyp=gSky.mVOSkyp;
stop_glerror();
if(!gGLManager.mHasMultitexture)
{
//Ack!Nomultitexture!Bail!
return;
}
LLFace*refl_face=voskyp->getReflFace();
gPipeline.disableLights();
LLGLDepthTestgls_depth(GL_TRUE,GL_FALSE);
LLGLDisablecullFace(GL_CULL_FACE);
//Setupsecondpassfirst
mWaterImagep->addTextureStats(1024.f*1024.f);
gGL.getTexUnit(1)->activate();
gGL.getTexUnit(1)->enable(LLTexUnit::TT_TEXTURE);
gGL.getTexUnit(1)->bind(mWaterImagep);
LLVector3camera_up=LLViewerCamera::getInstance()->getUpAxis();
F32up_dot=camera_up*LLVector3::z_axis;
LLColor4water_color;
if(LLViewerCamera::getInstance()->cameraUnderWater())
{
water_color.setVec(1.f,1.f,1.f,0.4f);
}
else
{
water_color.setVec(1.f,1.f,1.f,0.5f*(1.f+up_dot));
}
glColor4fv(water_color.mV);
//Automaticallygeneratetexturecoordsfordetailmap
glEnable(GL_TEXTURE_GEN_S);//textureunit1
glEnable(GL_TEXTURE_GEN_T);//textureunit1
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
//Slowlymoveovertime.
F32offset=fmod(gFrameTimeSeconds*2.f,100.f);
F32tp0[4]={16.f/256.f,0.0f,0.0f,offset*0.01f};
F32tp1[4]={0.0f,16.f/256.f,0.0f,offset*0.01f};
glTexGenfv(GL_S,GL_OBJECT_PLANE,tp0);
glTexGenfv(GL_T,GL_OBJECT_PLANE,tp1);
gGL.getTexUnit(1)->setTextureColorBlend(LLTexUnit::TBO_MULT,LLTexUnit::TBS_TEX_COLOR,LLTexUnit::TBS_PREV_COLOR);
gGL.getTexUnit(1)->setTextureAlphaBlend(LLTexUnit::TBO_REPLACE,LLTexUnit::TBS_PREV_ALPHA);
gGL.getTexUnit(0)->activate();
glClearStencil(1);
glClear(GL_STENCIL_BUFFER_BIT);
LLGLEnablegls_stencil(GL_STENCIL_TEST);
glStencilOp(GL_KEEP,GL_REPLACE,GL_KEEP);
glStencilFunc(GL_ALWAYS,0,0xFFFFFFFF);
for(std::vector::iteratoriter=mDrawFace.begin();
iter!=mDrawFace.end();iter++)
{
LLFace*face=*iter;
if(voskyp->isReflFace(face))
{
continue;
}
gGL.getTexUnit(0)->bind(face->getTexture());
face->renderIndexed();
}
//Now,disabletexturecoordgenerationontexturestate1
gGL.getTexUnit(1)->activate();
gGL.getTexUnit(1)->unbind(LLTexUnit::TT_TEXTURE);
gGL.getTexUnit(1)->disable();
glDisable(GL_TEXTURE_GEN_S);//textureunit1
glDisable(GL_TEXTURE_GEN_T);//textureunit1
//Disabletexturecoordinateandcolorarrays
gGL.getTexUnit(0)->activate();
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
stop_glerror();
if(gSky.mVOSkyp->getCubeMap())
{
gSky.mVOSkyp->getCubeMap()->enable(0);
gSky.mVOSkyp->getCubeMap()->bind();
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
LLMatrix4camera_mat=LLViewerCamera::getInstance()->getModelview();
LLMatrix4camera_rot(camera_mat.getMat3());
camera_rot.invert();
glLoadMatrixf((F32*)camera_rot.mMatrix);
glMatrixMode(GL_MODELVIEW);
LLOverrideFaceColoroverrid(this,1.f,1.f,1.f,0.5f*up_dot);
gGL.getTexUnit(0)->setTextureBlendType(LLTexUnit::TB_MULT);
for(std::vector::iteratoriter=mDrawFace.begin();
iter!=mDrawFace.end();iter++)
{
LLFace*face=*iter;
if(voskyp->isReflFace(face))
{
//refl_face=face;
continue;
}
if(face->getGeomCount()>0)
{
face->renderIndexed();
}
}
gGL.getTexUnit(0)->setTextureBlendType(LLTexUnit::TB_MULT);
gSky.mVOSkyp->getCubeMap()->disable();
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
}
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
if(refl_face)
{
glStencilFunc(GL_NOTEQUAL,0,0xFFFFFFFF);
renderReflection(refl_face);
}
gGL.getTexUnit(0)->setTextureBlendType(LLTexUnit::TB_MULT);
}Example#270ShowfileFile:
World.cpp
Project:
Dracotorre/CS447//*********************************************************************
//renderthescene
voidWorld::vrender(void)
{
Vec3DcamPos=m_cam->getPosition();
Vec3DlookAt=m_cam->getLookAt();
gluLookAt(camPos[0],camPos[1],camPos[2],
lookAt[0],lookAt[1],lookAt[2],
0.0f,1.0f,0.0f);
//drawtheshadowsfirst
//usedtutorialandadjustedasexplainedinthetext(Hawkins470).
glPushMatrix();
glLightfv(GL_LIGHT0,GL_POSITION,m_lightPosition);
setShadowMatrix();
//setupthestencilbuffersothatweonlydrawtheshadow
//onthereflectingsurface
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS,3,0xFFFFFFFF);
glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
m_floor->vrender();
glStencilFunc(GL_LESS,2,0xFFFFFFFF);
glStencilOp(GL_REPLACE,GL_REPLACE,GL_REPLACE);
glEnable(GL_POLYGON_OFFSET_FILL);
//drawtheshadowashalf-blendedblack
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDisable(GL_FOG);
glColor4f(0.0,0.0,0.0,0.5);
//projecttheobjectsthroughtheshadowmatrix
glMultMatrixf(m_shadowMatrix);
m_dome->vrender();
m_lamp->vrender();
m_endTable->vrender();
m_torus->vrender();
m_pawn->vrender();
glDisable(GL_BLEND);
glEnable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glEnable(GL_FOG);
glDisable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_STENCIL_TEST);
glPopMatrix();
//nowdrawtherealobjects
glPushMatrix();
glLightfv(GL_LIGHT0,GL_POSITION,m_lightPosition);
glCallList(m_dList);//putintheboringwalls
//thefloorgetsdrawnintheshadowssection
m_dome->vrender();
m_lamp->vrender();
m_endTable->vrender();
m_torus->vrender();
m_pawn->vrender();
glPopMatrix();
return;
}Example#280ShowfileFile:
gl_state.cpp
Project:
FenrisulfrX/citravoidOpenGLState::Apply()const{
//Culling
if(cull.enabled!=cur_state.cull.enabled){
if(cull.enabled){
glEnable(GL_CULL_FACE);
}else{
glDisable(GL_CULL_FACE);
}
}
if(cull.mode!=cur_state.cull.mode){
glCullFace(cull.mode);
}
if(cull.front_face!=cur_state.cull.front_face){
glFrontFace(cull.front_face);
}
//Depthtest
if(depth.test_enabled!=cur_state.depth.test_enabled){
if(depth.test_enabled){
glEnable(GL_DEPTH_TEST);
}else{
glDisable(GL_DEPTH_TEST);
}
}
if(depth.test_func!=cur_state.depth.test_func){
glDepthFunc(depth.test_func);
}
//Depthmask
if(depth.write_mask!=cur_state.depth.write_mask){
glDepthMask(depth.write_mask);
}
//Colormask
if(color_mask.red_enabled!=cur_state.color_mask.red_enabled||
color_mask.green_enabled!=cur_state.color_mask.green_enabled||
color_mask.blue_enabled!=cur_state.color_mask.blue_enabled||
color_mask.alpha_enabled!=cur_state.color_mask.alpha_enabled){
glColorMask(color_mask.red_enabled,color_mask.green_enabled,color_mask.blue_enabled,
color_mask.alpha_enabled);
}
//Stenciltest
if(stencil.test_enabled!=cur_state.stencil.test_enabled){
if(stencil.test_enabled){
glEnable(GL_STENCIL_TEST);
}else{
glDisable(GL_STENCIL_TEST);
}
}
if(stencil.test_func!=cur_state.stencil.test_func||
stencil.test_ref!=cur_state.stencil.test_ref||
stencil.test_mask!=cur_state.stencil.test_mask){
glStencilFunc(stencil.test_func,stencil.test_ref,stencil.test_mask);
}
if(stencil.action_depth_fail!=cur_state.stencil.action_depth_fail||
stencil.action_depth_pass!=cur_state.stencil.action_depth_pass||
stencil.action_stencil_fail!=cur_state.stencil.action_stencil_fail){
glStencilOp(stencil.action_stencil_fail,stencil.action_depth_fail,
stencil.action_depth_pass);
}
//Stencilmask
if(stencil.write_mask!=cur_state.stencil.write_mask){
glStencilMask(stencil.write_mask);
}
//Blending
if(blend.enabled!=cur_state.blend.enabled){
if(blend.enabled){
glEnable(GL_BLEND);
cur_state.logic_op=GL_COPY;
glLogicOp(cur_state.logic_op);
glDisable(GL_COLOR_LOGIC_OP);
}else{
glDisable(GL_BLEND);
glEnable(GL_COLOR_LOGIC_OP);
}
}
if(blend.color.red!=cur_state.blend.color.red||
blend.color.green!=cur_state.blend.color.green||
blend.color.blue!=cur_state.blend.color.blue||
blend.color.alpha!=cur_state.blend.color.alpha){
glBlendColor(blend.color.red,blend.color.green,blend.color.blue,blend.color.alpha);
}
if(blend.src_rgb_func!=cur_state.blend.src_rgb_func||
blend.dst_rgb_func!=cur_state.blend.dst_rgb_func||
blend.src_a_func!=cur_state.blend.src_a_func||
blend.dst_a_func!=cur_state.blend.dst_a_func){
glBlendFuncSeparate(blend.src_rgb_func,blend.dst_rgb_func,blend.src_a_func,
blend.dst_a_func);
}
if(blend.rgb_equation!=cur_state.blend.rgb_equation||
blend.a_equation!=cur_state.blend.a_equation){
glBlendEquationSeparate(blend.rgb_equation,blend.a_equation);
}
if(logic_op!=cur_state.logic_op){
glLogicOp(logic_op);
}
//Textures
for(unsignedi=0;i=0){
glPushMatrix();
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_EQUAL,10,~0);
glStencilOp(GL_KEEP,GL_KEEP,GL_ZERO);
glTranslatef(xPos,0.02f,zPos);
TextureManager::getInstance()->toggleTextures();
shadowMatrix(0-xPos,12,0-zPos,1.0f);
glColor4f(0.0,0.0,0.0,calculateAlpha(0,0,rows,columns));
model->draw();
//draw();
TextureManager::getInstance()->toggleTextures();
glDisable(GL_STENCIL_TEST);
glPopMatrix();
}
if(calculateAlpha(0,rows,rows,columns)>=0){
glPushMatrix();
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_EQUAL,10,~0);
glStencilOp(GL_KEEP,GL_KEEP,GL_ZERO);
glTranslatef(xPos,0.02f,zPos);
TextureManager::getInstance()->toggleTextures();
shadowMatrix(0-xPos,12,rows-zPos,1.0f);
glColor4f(0.0,0.0,0.0,calculateAlpha(0,rows,rows,columns));
model->draw();
//draw();
TextureManager::getInstance()->toggleTextures();
glDisable(GL_STENCIL_TEST);
glPopMatrix();
}
if(calculateAlpha(columns,0,rows,columns)>=0){
glPushMatrix();
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_EQUAL,10,~0);
glStencilOp(GL_KEEP,GL_KEEP,GL_ZERO);
glTranslatef(xPos,0.02f,zPos);
TextureManager::getInstance()->toggleTextures();
shadowMatrix(columns-xPos,12,0-zPos,1.0f);
glColor4f(0.0,0.0,0.0,calculateAlpha(columns,0,rows,columns));
model->draw();
//draw();
TextureManager::getInstance()->toggleTextures();
glDisable(GL_STENCIL_TEST);
glPopMatrix();
}
if(calculateAlpha(columns,rows,rows,columns)>=0){
glPushMatrix();
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_EQUAL,10,~0);
glStencilOp(GL_KEEP,GL_KEEP,GL_ZERO);
glTranslatef(xPos,0.02f,zPos);
TextureManager::getInstance()->toggleTextures();
shadowMatrix(columns-xPos,12,rows-zPos,1.0f);
glColor4f(0.0,0.0,0.0,calculateAlpha(columns,rows,rows,columns));
model->draw();
//draw();
TextureManager::getInstance()->toggleTextures();
glDisable(GL_STENCIL_TEST);
glPopMatrix();
}
//}
//glDisable(GL_TEXTURE_2D);
//glDisable(GL_STENCIL_TEST);
//glPopMatrix();
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glEnable(GL_LIGHTING);
//glEnable(GL_COLOR_MATERIAL);
//}
}x