Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mukela · May 08, 2013 at 06:27 PM · texturelightingreflectionopengl

making lighting inside a cube and reflecting the image

i'm trying to make the light shine inside my cube and reflect the image on the bottom of my cube,i am trying to make this work but it seems i keep failing what exactly am i supposed to do,may some one explain to me,what i should add to this code below

 void drawScene() {
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
     
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
     
     glTranslatef(0.0f, 0.0f, -40.0f);
     glRotatef(30, 1, 0, 0);
     
     GLfloat ambientLight[] = {0.3f, 0.3f, 0.3f, 1.0f};
     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);
     
     GLfloat lightColor[] = {0.7f, 0.7f, 0.7f, 1.0f};
     GLfloat lightPos[] = {-2 * BOX_SIZE, BOX_SIZE, 4 * BOX_SIZE, 1.0f};
     glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
     glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
     
     glPushMatrix();
     glTranslatef(0, BOX_HEIGHT, 0);
     drawCube(_textureId, _angle);
     glPopMatrix();
     
     glEnable(GL_STENCIL_TEST); //Enable using the stencil buffer
     glColorMask(0, 0, 0, 0); //Disable drawing colors to the screen
     glDisable(GL_DEPTH_TEST); //Disable depth testing
     glStencilFunc(GL_ALWAYS, 1, 1); //Make the stencil test always pass
     //Make pixels in the stencil buffer be set to 1 when the stencil test passes
     glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
     //Set all of the pixels covered by the floor to be 1 in the stencil buffer
     drawFloor(_textureId);
     
     glColorMask(1, 1, 1, 1); //Enable drawing colors to the screen
     glEnable(GL_DEPTH_TEST); //Enable depth testing
     //Make the stencil test pass only when the pixel is 1 in the stencil buffer
     glStencilFunc(GL_EQUAL, 1, 1);
     glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); //Make the stencil buffer not change
     
     //Draw the cube, reflected vertically, at all pixels where the stencil
     //buffer is 1
     glPushMatrix();
     glScalef(1, -1, 1);
     glTranslatef(0, BOX_HEIGHT, 0);
     drawCube(_textureId, _angle);
     glPopMatrix();
     
     glDisable(GL_STENCIL_TEST); //Disable using the stencil buffer
     
     //Blend the floor onto the screen
     glEnable(GL_BLEND);
     glColor4f(1, 1, 1, 0.7f);
     drawFloor(_textureId);
     glDisable(GL_BLEND);
     
     glutSwapBuffers();
 }

and my cube code is this one below

 void drawCube(int textureId, float angle) {
     glDisable(GL_TEXTURE_2D);
     
     glPushMatrix();
      glRotatef( rotate_x, 1.0, 0.0, 0.0 );
   glRotatef( rotate_y, 0.0, 1.0, 0.0 );
 
     
     glBegin(GL_QUADS);
     
 
     //Bottom face
     glColor3f(1.0f, 0.0f, 1.0f);
     glNormal3f(0.0, -1.0f, 0.0f);
     glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);
     glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);
     glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);
     glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);
     
     //Left face
 /*    
     //Right face
     glNormal3f(1.0, 0.0f, 0.0f);
     glColor3f(1.0f, 0.0f, 0.0f);
     glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);
     glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);
     glColor3f(0.0f, 1.0f, 0.0f);
     glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);
     glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);
     */
     glEnd();
     glEnable(GL_TEXTURE_2D);
     glBindTexture(GL_TEXTURE_2D, textureId);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     glColor3f(1.0f, 1.0f, 1.0f);
     glBegin(GL_QUADS);
     
     //Front face
     glNormal3f(0.0, 0.0f, 1.0f);
     glTexCoord2f(0.0f, 0.0f);
     glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);
     glTexCoord2f(1.0f, 0.0f);
     glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);
     glTexCoord2f(1.0f, 1.0f);
     glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);
     glTexCoord2f(0.0f, 1.0f);
     glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);
 
     glNormal3f(-1.0, 0.0f, 0.0f);
     glTexCoord2f(0.0f, 0.0f);
     glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);
     glTexCoord2f(1.0f, 0.0f);
     glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);
     glTexCoord2f(1.0f, 0.0f);
     glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);
     glTexCoord2f(1.0f, 0.0f);
     glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);
     
     
     //Back face
     glNormal3f(0.0, 0.0f, -1.0f);
     glTexCoord2f(0.0f, 0.0f);
     glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);
     glTexCoord2f(1.0f, 0.0f);
     glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);
     glTexCoord2f(1.0f, 1.0f);
     glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, -BOX_SIZE / 2);
     glTexCoord2f(0.0f, 1.0f);
     glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, -BOX_SIZE / 2);
     
     glEnd();
     
     glPopMatrix();
 }

 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Textures different between editor and device 1 Answer

Reflective surface/texture bug in build only (works in play mode in editor) 1 Answer

How can I get a similar reflective effect to that of the lockers of Outlast 2? 0 Answers

Creating a mirror effect 1 Answer

How to prevent Overlapping Lights from combining / adding intensity? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges