Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: stencil buffer question

  1. #1

    stencil buffer question

    hello. 1) I have last days by any chance and fixed a stencil buffer example from this board. that took over one hour to find an undesigned char! the sub a() was infected I deleted this part complete and renamed this sub new by hand into sub ax() and changed "Pointer" into "long".

    stencil buffer is a limitation of a certain rendering area. you can stencil a white/black colour buffer and copy it like a clipping plane and mirror a scene with new content (like a bluebox) where nothing is drawn before. but I am asking myself if this showing example is correct and serve fully with this techniques ? perhaps somebody can check and give more closer infos about this code example!

    2) Attention! This stencil example I fixed works only with an old "thinbasic_tbgl.dll" (around 271 kbyte). I found this dll ! it's old but this special example works with this "thinbasic_tbgl.dll", I am glad. now I am understanding this example! the sphere use colour stencil from second sphere, cut the half sphere and "copied" this colour inside first sphere!

    bye, largo
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by largo_winch; 16-08-2011 at 16:16.

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    The old TBGL you link is more like experimetal one, stencil buffer was never enabled by default in TBGL. I will think about how to make possible to use stencil with in future in TBGL, if there will be enough interest.

    The concept of stencil is very straightforward, but I do not remember the last time I really needed it in application, that's why it is not present at the moment.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3

    stencil scene power

    if you need a working example you can help to use this little but great idea a) stencil buffer as a "mirror" does function exactly reverse modus. you don't want to see a fighter (star wars) in front of a mirror shining through mirror side behind the wall. here the stencil buffer is working.

    b) if you are taking a aeroplane cockpit and extract only cockpit colors, take a sky (with blue cloud) bitmap and "stencil" black-white modus out and "stencil" (copy for this way) this sky texture to cockpit you will have a new environment for you aeroplane cockpit

    I add a "non-working-pure-script-example" have to run for thinbasic too, I am very sure. I have not the time to check this example, but I know this is running. take a 3d model (figure by zygote, poser or such things) and place it in front of a mirror and wall scene (alternative a dungeon area). I will try to build this example with own power

    Code snippet:

    [thinbasic=code] 'constant ClipPlane : array[0..3] of Double = (0, 0, -1, 0); // Löschen des Stencil-Puffers zum Beginn der Szene // Delete Stencil-Buffer at start of scene glClear(GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT or GL_STENCIL_BUFFER_BIT); glColorMask(False, False, False, False); glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glDisable(GL_DEPTH_TEST); glDisable(GL_TEXTURE_2D); DrawMirror; glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); glColorMask(True, True, True, True); glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glEnable(GL_CLIP_PLANE0); glClipPlane(GL_CLIP_PLANE0, @ClipPlane); glScalef(1,1,-1) 'mirrorscene green/red with star wars fighter glDisable(GL_CLIP_PLANE0); glDisable(GL_STENCIL_TEST); '-----------------------> draw the mirror --------------> glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1,1,1,0.45); MirrorTex.Bind; DrawMirror; glDisable(GL_BLEND); '-----------------------> draw the mirror --------------> [/code]

    bye, largo
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by largo_winch; 16-08-2011 at 20:29.

  4. #4

    possible way to mirror material?

    hello petr. can you check if these code lines are compatible for tbgl?

    Global mFloor As Long = TBGL_NewMaterial
    TBGL_UseBlend %TRUE
    TBGL_BlendFunc(%GL_SRC_ALPHA, %GL_ONE_MINUS_SRC_ALPHA)
    TBGL_ColorAlpha(0.7, 0.0, 0.0, 0.40)
    TBGL_SetMaterialDiffuse(mFloor, 0, 0, 255) '0
    TBGL_SetMaterialAmbient(mFloor, 255, 255, 255)
    TBGL_SetMaterialSpecular(mFloor, 255, 255, 255)
    TBGL_SetMaterialSpecularExponent(mFloor, 12
    TBGL_UseBlend %FALSE

    '------------------------------------------------------------------------> 'gl_Enable(GL_BLEND);
    'glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    'glColor4f(0.7, 0.0, 0.0, 0.40); /* 40% dark red floor color */
    'drawFloor();
    'glDisable(GL_BLEND);
    '------------------------------------------------------------------------>

    I send a tbasic file with new material ideas.

    bye, largo
    Attached Images Attached Images
    Attached Files Attached Files

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hello!,

    blending is not part of the material definition at the moment, to achieve blended torus, you should enable it in the *_Render entity callback.

    I am not decided whether to add blending to material definition, but I just developed optional alpha component for diffuse/ambient/specular, so instead of TBGL_ColorAlpha you will be able to specify:
    TBGL_SetMaterialDiffuse(mFloor, 0.7*255, 0.0, 0.0, 0.40*255)
    
    in ThinBASIC 1.8.9.0, once it is released.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    To not make you wait,

    improved TBGL with TBGL_SetMaterialAmbient, TBGL_SetMaterialDiffuse and TBGL_SetMaterialSpecular is available here (including updated documentation).


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  7. #7

    transparent material possible?

    hello petr. thanks for your last edition of "SetMaterialDiffuse" tbgl update!

    1)Do you know if it's possible to create a transparent material?

    'TESTING ----------------------------------------------->
    Global mAlpha As Long = TBGL_NewMaterial ''mat_transparent(1)
    TBGL_SetMaterialDiffuse(mAlpha, 0.7*255, 0.0, 0.0, 0.40*255)
    'TBGL_SetMaterialEmission(mAlpha, 0, 0, 255)
    TBGL_SetMaterialAmbient(mAlpha, 0, 0, 255)
    TBGL_SetMaterialSpecular(mAlpha, 255, 255, 255)
    TBGL_SetMaterialSpecularExponent(mAlpha, 64)

    2) Does "TBGL_SetMaterialEmission" command is existing?


    3) Sub Sphere_Render()
    Dim element As TBGL_TENTITYIDENTIFIER At TBGL_CallingEntity
    Dim material As Long At TBGL_EntityGetUserDataPointer(element.scene, element.entity)

    TBGL_PushMaterial(material)
    'TBGL_Translate -0.15, -0.15, 0.1+solidZ
    'TBGL_Translate 0.15, 0.15, transparentZ
    TBGL_Torus 0.2, 0.8
    TBGL_PopMaterial
    End Sub

    How I can translate object position for this example with adding variables to z-coordinate?

    that's all

    bye, largo

  8. #8

    demo example and pic

    I am sending current example (attention: only for test demo, not perfect!) and picture!
    4) does 'TBGL_DepthMask %GL_FALSE (%GL_TRUE) command exists?

    bye, largo
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by largo_winch; 26-08-2011 at 13:49.

  9. #9
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Largo,

    1)
    as I wrote earlier:
    I am not decided whether to add blending to material definition
    So short answer is - not present at the moment.

    2)
    Regarding TBGL_SetMaterialEmission, do you have any particular use for it? I did not used emissive property in my work so far, so I didn't add it to TBGL either.
    Which material would you like to model with emission?

    To check whether command exists, you can simply write it in the editor and hit F1. If you don't get help for it, than it is not existing.
    If you would like to see some feature, please do not hesitate to request one item at time(ideally with description including motivation) in TBGL support section (just click Post new issue/Feature).

    3)
    You can use TBGL_EntityPush to push object in local coordinates, or TBGL_EntityMove to move object in global coordinates.
    The way you did is also possible (presuming solidZ, transparentZ are globals), but it is not wise from modular design point of view.

    4)
    I think that what you seek is called TBGL_UseDepthMask in ThinBASIC.

    I hope it helps, let me know


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  10. #10

    setMaterialEmission, setMaterialShininess

    thank you again for infos, petr! I cannot popup "new issue" for tbgl_section you linked from my pc, sorry. perhaps you can push it to right place.

    please add for next tbgl and thinbasic issues:

    1) //Add for light/material

    'ok void setMaterialAmbient (GLfloat r, GLfloat g, GLfloat b);
    'ok void setMaterialDiffuse (GLfloat r, GLfloat g, GLfloat b);
    'ok void setMaterialSpecular (GLfloat r, GLfloat g, GLfloat b);

    missing: void setMaterialEmission (GLfloat r, GLfloat g, GLfloat b);
    missing: void setMaterialShininess (GLfloat s);

    "setMaterialEmission" you can use for example for "candle light" material

    2) a) glEnable(GL_BLEND), b) glDisable(GL_BLEND)

    I can wait until next release no problem. thank you for your great tbgl efforts until today!

    3) general question: do you have had problems to mix different libraries (as you already have mentioned) for creation your tbgl graphic library?

    bye, largo

Page 1 of 2 12 LastLast

Similar Threads

  1. How to read the keyboard buffer?
    By Michael Hartlef in forum thinBasic General
    Replies: 7
    Last Post: 18-05-2009, 08:47
  2. UDT question
    By sandyrepope in forum thinBasic General
    Replies: 3
    Last Post: 18-02-2008, 22:33

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •