Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After some experimentation, I think that I've found a solution that appears to be suitable for my own purposes. First, given the example code in my question above, it appears that the pixmap needs to be passed to the <code>glDrawPixels</code> function as an array <code>GLubyte color[2][2][4]</code> with an alpha channel. As mentioned by Vaayu, there is also a possibility that the <code>glMatrixMode</code> function needs to be set up correctly. Second, according to pg. 356 of the OpenGL Programming Guide (7th Edition), the current raster position needs to be set if the <code>glPixelZoom</code> function is called with negative arguments. Essentially why I couldn't see an image was due to the raster being drawn at a position not within the viewable area of the window. The following code demonstrates how to set the rotation and the current raster position for four separate cases:</p> <p><pre><code> // case 0 glWindowPos2i(0, 0); glPixelZoom(scaleX, scaleY);</p> <p>// case 1 glWindowPos2i(windowHeight, 0); glPixelZoom(-scaleX, scaleY);</p> <p>// case 2 glWindowPos2i(0, windowHeight); glPixelZoom(scaleX, -scaleY);</p> <p>// case 3 glWindowPos2i(windowWidth, windowHeight); glPixelZoom(-scaleX, -scaleY); </pre></code></p> <p>So the example given in my original question can be updated:</p> <pre> class Pixmap { public: GLubyte color[2][2][4]; Pixmap() { // red color[0][0][0] = 255; color[0][0][1] = 0; color[0][0][2] = 0; color[0][0][3] = 0; // green color[0][1][0] = 0; color[0][1][1] = 255; color[0][1][2] = 0; color[0][1][3] = 0; // blue color[1][0][0] = 0; color[1][0][1] = 0; color[1][0][2] = 255; color[1][0][3] = 0; // white color[1][1][0] = 255; color[1][1][1] = 255; color[1][1][2] = 255; color[1][1][3] = 0; } void render() { glClear(GL_COLOR_BUFFER_BIT); glDrawPixels( 2, 2, GL_RGBA, 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; int rotation; // Choose rotation case {0, 1, 2, 3} rotation = 3; glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); 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_MODELVIEW); // Select rotation switch(rotation) { case 0: glWindowPos2i(0, 0); glPixelZoom(scaleX, scaleY); break; case 1: glWindowPos2i(windowHeight, 0); glPixelZoom(-scaleX, scaleY); break; case 2: glWindowPos2i(0, windowHeight); glPixelZoom(scaleX, -scaleY); break; case 3: glWindowPos2i(windowWidth, windowHeight); glPixelZoom(-scaleX, -scaleY); break; default: break; } glClearColor(1.0, 1.0, 1.0, 0.0); glColor3f(0.0f, 0.0f, 0.0f); glutDisplayFunc( myRender ); glutMainLoop(); } </pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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