Hello guys,
I m newcomer to OpenGL and so far I have learned on how to use GlDrawpixels(…). I succeeded in rendering 1 color (using GL_LUMINANCE). However, when I used GL_RGB for 256color, the animation frames overlap each other. It is weird because it worked fine for 1-color. Can someone give me any hint whats going on? Here is a bit of mycode.
#include <GL/glut.h>
#include <GL/gl.h>
#include <math.h>
#include <string.h>
#define NS_WINSIZE 512
const float PI=3.14159265358979;
float XPoint(float,float, float,float, float,float);
float YPoint(float,float, float,float, float,float);
void fractal(float,float,int,const float);
unsigned char img1[NS_WINSIZE * NS_WINSIZE][3];
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
for (unsigned int i = 0; i < 48; i++)
{
memset(img1,0, NS_WINSIZE * NS_WINSIZE);
fractal(0,0,20,PI*i/24);
glDrawPixels(NS_WINSIZE, NS_WINSIZE, GL_RGB, GL_UNSIGNED_BYTE, img1);
glFlush();
}
}
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitWindowSize(NS_WINSIZE, NS_WINSIZE);
glutCreateWindow("Fractal Viewer");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
float XPoint(float xc,float yc, float theta,float scale, float x,float y){
return ((x*cos(theta)-y*sin(theta))*scale+xc);
}
float YPoint(float xc,float yc, float theta,float scale, float x,float y){
return ((x*sin(theta)+y*cos(theta))*scale+yc);
}
void fractal(float x, float y, int depth, const float ang) {
if (depth==0) {
int xc,yc;
xc = int( (x-(-2)) * NS_WINSIZE/4);
yc = int( (y-(-2)) * NS_WINSIZE/4);
img1[NS_WINSIZE*yc+xc][0]=204;
img1[NS_WINSIZE*yc+xc][1]=51;
img1[NS_WINSIZE*yc+xc][2]=153;
} else {
fractal(XPoint(1,0,0+ang,.70710678,x,y),YPoint(1,0,0+ang,.70710678,x,y),depth-1,ang);
fractal(XPoint(-1,0,0-ang,.70710678,x,y),YPoint(-1,0,0-ang,.70710678,x,y),depth-1,ang);
}
}
The colors blend works well. The only problem is overlapping frames.