Jump to content
  • Advertisement
Sign in to follow this  
binlee

ask glReadPixels(stencil)

This topic is 4579 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

the source codes as follow: #include <GL/glut.h> #include <GL/gl.h> #include <gl/glaux.h> #include <GL/glu.h> #include <stdlib.h> #include <stdio.h> #define YELLOWMAT 1 #define BLUEMAT 2 void init(void) { GLfloat yellow_diffuse[]={0.7, 0.7, 0.0, 1.0}; GLfloat yellow_specular[]={1.0, 1.0, 1.0, 1.0}; GLfloat blue_diffuse[]={0.1, 0.1, 0.7, 1.0}; GLfloat blue_specular[]={0.1, 1.0, 1.0, 1.0}; GLfloat position_one[]={1.0, 1.0, 1.0, 0.0}; glNewList(YELLOWMAT, GL_COMPILE); glMaterialfv(GL_FRONT, GL_DIFFUSE, yellow_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, yellow_specular); glMaterialf(GL_FRONT, GL_SHININESS, 64.0); glEndList(); glNewList(BLUEMAT, GL_COMPILE); glMaterialfv(GL_FRONT, GL_DIFFUSE, blue_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, blue_specular); glMaterialf(GL_FRONT, GL_SHININESS, 45.0); glEndList(); glLightfv(GL_LIGHT0, GL_POSITION, position_one); glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); glClearStencil(0x0); glEnable(GL_STENCIL_TEST); } void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glStencilFunc(GL_EQUAL, 0x1, 0xFFFF); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); //glStencilFunc(GL_EQUAL, 0x0, 0x3FF); //glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); //glStencilOp(GL_KEEP, GL_INCR, GL_KEEP); //glStencilOp(GL_KEEP, GL_INCR, GL_INCR); glCallList(BLUEMAT); glutSolidSphere(0.5, 15, 15); /* GLint *params=0 ; glGetIntegerv(GL_STENCIL_VALUE_MASK, params); glStencilFunc(GL_NOTEQUAL, 0x1, *params);*/ //glStencilFunc(GL_NOTEQUAL, 0x0, 0x3FF); glStencilFunc(GL_NOTEQUAL, 0x1, 0xFFFF); glPushMatrix(); glRotatef(45.0, 0.0, 0.0, 1.0); glRotatef(45.0, 0.0, 1.0, 0.0); glCallList(YELLOWMAT); glutSolidTorus(0.275, 0.85, 15, 15); glPushMatrix(); glRotatef(90.0, 1.0, 0.0, 0.0); glutSolidTorus(0.275, 0.85, 15, 15); glPopMatrix(); } void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w<=h) gluOrtho2D(-3.0, 3.0, -3.0*(GLfloat)h/(GLfloat)w, 3.0*(GLfloat)h/(GLfloat)w); else gluOrtho2D(-3.0*(GLfloat)w/(GLfloat)h, 3.0*(GLfloat)w/(GLfloat)h, -3.0, 3.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear(GL_STENCIL_BUFFER_BIT); glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS, 0x1, 0xFFFF); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); //glStencilOp(GL_REPLACE, GL_KEEP, GL_REPLACE); //glStencilOp(GL_KEEP, GL_REPLACE, GL_KEEP); glBegin(GL_QUADS); glVertex2f(-1.0, 0.0); glVertex2f(0.0, 1.0); glVertex2f(1.0, 0.0); glVertex2f(0.0, -1.0); glEnd(); GLubyte*pixels; pixels= new GLubyte[w*h]; glReadPixels(0,0,w,h, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE,pixels); delete []pixels; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, (GLfloat)w/(GLfloat)h, 3.0, 7.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, -5.0); } int main(int argc, char ** argv) { glutInit(&argc, argv); //glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH | GLUT_STENCIL); glutInitWindowSize(500,500); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glutReshapeFunc(reshape); //glutKeyboardFunc(keyboard); glutDisplayFunc(display); glutMainLoop(); return (0); } in this code, i want to read the value of stencil buffer, but it doesn't succeed! "glReadPixels(0,0,w,h, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE,pixels);" what is wrong? however, i could use "glReadPixels(0,0,w,h, GL_DEPTH_COMPONENT, GL_FLOAT,pixels);" to get the value of the value of the depth buffer. why? how to read the value of the stencil buffer? could you tell me ? thanks a lot.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!