Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying pixmap with glDrawPixels
    primarykey
    data
    text
    <p>I've written a small example program using OpenGL and GLUT to display a 2-by-2 grid of four colored squares using the <code>glDrawPixels</code> function. Unfortunately, I've found that: </p> <ol> <li>The colors in the grid are not being displayed properly; and</li> <li>When the glPixelZoom function is passed negative arguments to rotate the pixmap, nothing is displayed in the window.</li> </ol> <p>The following C++ code snippet displays the example image. What am I doing wrong here, and what should I change to be able to view the intended colors and rotate the pixmap?</p> <pre><code> struct RGB { unsigned char r, g, b; }; class Pixmap { public: RGB color[4]; Pixmap() { color[0].r = 255; color[0].g = 0; color[0].b = 0; color[1].r = 0; color[1].g = 255; color[1].b = 0; color[2].r = 0; color[2].g = 0; color[2].b = 255; color[3].r = 255; color[3].g = 255; color[3].b = 255; } void render() { glClear(GL_COLOR_BUFFER_BIT); glDrawPixels( 2, 2, GL_RGB, GL_UNSIGNED_BYTE, color ); glFlush(); } }; // Create an instance of class Pixmap Pixmap myPixmap; void myRender() { myPixmap.render(); } int main( int argc, char *argv[] ) { int screenWidth, screenHeight; glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); screenWidth = glutGet(GLUT_SCREEN_WIDTH); screenHeight = glutGet(GLUT_SCREEN_HEIGHT); int windowWidth = screenHeight / 2; int windowHeight = screenHeight / 2; glutInitWindowSize(windowWidth, windowHeight); int posX = (screenWidth - windowWidth) / 2; int posY = (screenHeight - windowHeight) / 4; glutInitWindowPosition(posX, posY); glutCreateWindow("Picture"); GLfloat scaleX = 1.0f * windowWidth / 2; GLfloat scaleY = 1.0f * windowHeight / 2; glMatrixMode( GL_PROJECTION ); // If glPixelZoom(-scaleX, scaleY) // then no image is displayed glPixelZoom(scaleX, scaleY); glClearColor(1.0, 1.0, 1.0, 0.0); glColor3f(0.0f, 0.0f, 0.0f); glutDisplayFunc( myRender ); glutMainLoop(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload