Skip to main content
GameDev.net gamedev.net
🔒 Locked

glDrawPixels

Started by prophete Aug 30, 2006 at 9:22 AM 3 replies 5.1k views
Original Post
prophete
prophete
Hi, anyone familiar with the glDrawPixels function? im having trouble displaying pixels on the screen..
Lord Faron
Lord Faron
What's the problem?
if (time() == $) { $ = 0; }
prophete
prophete
here's my code:

#include
#include
#include
#include


float pixels[256][256][3];


void myInit(void)
{
glClearColor(1.0,1.0,1.0,0.0); // set white background color
glColor3f(0.0f,0.0f,0.0f); // sets the drawing color to be red
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,256.0,0.0,256.0); // the transformation of the screen
}

void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT); // clear the screen
glDrawPixels(4.0, 4.0, GL_RGB, GL_FLOAT, **pixels);
glFlush(); // send ouput to display
}


void MyMouse(int button, int state, int x, int y)
{
if (button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
{
pixels[x][y][0]=255;
pixels[x][y][1]=0;
pixels[x][y][2]=0;
glDrawPixels(4.0, 4.0, GL_RGB, GL_FLOAT, pixels);
glFlush();
}

}

void myMovedMouse(int x, int y)
{
pixels[x][y][0]=255;
pixels[x][y][1]=0;
pixels[x][y][2]=0;
glDrawPixels(4.0, 4.0, GL_RGB, GL_FLOAT, pixels);
glFlush();
}

void color_menu(int id)
{
}

void createGLUTMenus() {

int menu,submenu;

submenu = glutCreateMenu(processMenuEvents);
glutAddMenuEntry("Red",1);
glutAddMenuEntry("Blue",2);
glutAddMenuEntry("Green",3);

menu = glutCreateMenu(processMenuEvents);
glutAddMenuEntry("White",WHITE);
glutAddSubMenu("Color Menu",submenu);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}





void main(int argc , char**argv)
{
int c_menu, f_menu, p_menu;

for (int i=0; i<256; i++)
for (int j=0; j<256; j++)
for (int k=0; k<3; k++)
pixels[j][k] = 0.0;

glutInit(&argc, argv); //initializes the toolkit

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //sets the display mode

glutInitWindowSize(256, 256); //set window size

glutInitWindowPosition(0,0); //set window position on screen

glutCreateWindow("Pixel Paint"); //open the screen window

glutDisplayFunc(myDisplay);

c_menu = glutCreateMenu(color_menu);
glutAddMenuEntry("Red", 1);
glutAddMenuEntry("Green", 2);
glutAddMenuEntry("Blue", 3);
glutAddMenuEntry("Cyan", 4);
glutAddMenuEntry("Yellow", 5);
glutAddMenuEntry("Eraser", 7);
glutAddMenuEntry("Fading brush", 8);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutAddSubMenu("Colors", c_menu);


glutMouseFunc(MyMouse);
glutMotionFunc(myMovedMouse);
myInit();

glutMainLoop(); //Starts executing the drawing code




}


i can't draw any pixel to the screen
Kalidor
Kalidor
Quote:
Original post by prophete
glDrawPixels(4.0, 4.0, GL_RGB, GL_FLOAT, pixels);
Are you sure you aren't drawing anything as opposed to just drawing a block of 16 pixels, say in the bottom-left corner of the screen? If you want to draw the entire pixels array you need to change the width and height parameters to glDrawPixels.

When posting large pieces of source code in the future, use the source tags.
gold
gold
You need to set the raster position. See glRasterPos or glWindowPos for details.

Note that WindowPos was promoted to the core in version 1.4 but I cannot find an online man page for it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.