Skip to main content
gamedev.net
🔒 Locked

Simple Paint Help

Started by fear4ever 1 reply 850+ views
Original Post
fear4ever
fear4ever
Hi ppl. I am trying to code a somewhat simple paint program.(c++) I was able to draw primitives like lines rectangles or triangles so far. I am using an array of structs to hold data about these primitives and in the display function i am clearing the screen and painting each element.Something like that.

glClearColor(1.0,1.0,1.0,1.0);  // Set the color to use in glClear.
glClear(GL_COLOR_BUFFER_BIT);   // Fill the window with the color.
drawItems();  // Draw all the items that the user has created.
glutSwapBuffers();  // Makes the drawing appear on the screen!


Now i need to implement a free brush and what random thing user draws cant be hold in a struct.(Just random dots god knows how many)So my initial design became useless for i cant call something like drawBrushTrails(). This will be impossibly difficult if i try to impelement "seed fill". So i tried to get all pixel color data and paint on it and reget the pixel data. Something like this. Irrelevant lines are exculuded.

void myGlutIdle( void )
{
   glReadBuffer(GL_BACK);
   glReadPixels(0,0,arrayW,arrayH,
		GL_RGB,GL_UNSIGNED_BYTE,(void *)pixelMap);
  glutPostRedisplay();
}
void display() {
   glDrawPixels(arrayW,arrayH,GL_RGB,GL_UNSIGNED_BYTE,pixelMap);//Paint all data
   drawItems();  // Draw all the items that the user has created.
   glutSwapBuffers();  // Makes the drawing appear on the screen!
}

However this isnt what i want either because now whatever user does stays on screen. For example while drawing a line user clicks somewhere marking the begging of a line, then moves the mouse to somewhere else and clicks a second time ti end drawing. But program shows intermediate lines (like ms paint) and they stay on screen making the whole approach useless. I am pretty sure some of you have already walked these paths. Any idea or link or code will be much appretiated.
fear4ever
fear4ever
No answers :( C'mon help me out
Xero-X2
Xero-X2
hmm im not quite certain if the approch works for you, but if you just create a texture, and then use the texture to draw the base img, then you can put anything you want over it, and you can update it like this

DrawBaseTexture();
DrawChange();
CopyTexture(); // Copys screen back to BaseTexture

and during regular funciton you just DrawBaseTexture(); and if you are doing some extra drawing for tools or such over it, just make sure you only apply changes to the texture after redrawing the base texture, with out the tools or such over it.

maybe this has given you an idea?
"I seek knowledge and to help those who also seek it"

Topic Locked

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

Sign in to reply to this topic.