Beispiel #1
0
void RecLoopRender::draw(){
    VideoFrame * bufferFrame = buffer->getNextVideoFrame();
    VideoFrame * liveFrame   = live->getNextVideoFrame();
    if(bufferFrame!=NULL && liveFrame!=NULL){
        if(!imageAllocated){
            image.allocate(liveFrame->getWidth(),liveFrame->getHeight(),OF_IMAGE_COLOR);
            imageAllocated=true;
        }

        ofEnableAlphaBlending();
        ofSetColor(tintR,tintG,tintB,alpha);
        if(minmaxBlend)
            glBlendEquationEXT(GL_MAX);
        else
            glBlendEquationEXT(GL_MIN);

        liveFrame->getTextureRef().draw(0,0);

        if(!stopped){
            bufferFrame->getTextureRef().draw(0,0);
			image.grabScreen(0,0,liveFrame->getWidth(),liveFrame->getHeight());
			bufferFrame->getTextureRef().loadData(image.getPixelsRef());
        }

        liveFrame->release();
        bufferFrame->release();

        ofDisableAlphaBlending();
        glBlendEquationEXT(GL_FUNC_ADD);

    }
}
Beispiel #2
0
void VideoRenderer::draw(){
	if(shaderActive)
		shader.begin();
	if(tint.a<255){
		ofEnableAlphaBlending();

		if(minmaxBlend){
			glBlendEquationEXT(GL_MAX);

			//glBlendFuncSeparateEXT( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_DST_ALPHA );
			//glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
			//glBlendEquationSeparateEXT(GL_MAX,GL_ADD);
		}else{
			glBlendEquationEXT(GL_MIN);


			//glBlendFuncSeparateEXT( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_DST_ALPHA );
			//glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
			//glBlendEquationSeparateEXT(GL_MIN,GL_ADD);
		}
		ofSetColor(tint);
		/// drawing the video render
		drawNextFrame();
		glBlendEquationEXT(GL_FUNC_ADD);
		ofDisableAlphaBlending();
	}else{
		ofSetColor(tint);
		drawNextFrame();
	}
	if(shaderActive)
		shader.end();

}
void render_highpassfilter_ext (float threshold_R, float threshold_G, float threshold_B) {

	// substract the threshold
	glBlendFunc (GL_ONE, GL_ONE);
	glBlendEquationEXT (GL_FUNC_REVERSE_SUBTRACT_EXT);
	glColor4f (threshold_R, threshold_G, threshold_B, 0);
	screenquad ();
	glBlendEquationEXT (GL_FUNC_ADD_EXT);
}
EXTERN_C_ENTER

JNIEXPORT void JNICALL Java_org_lwjgl_opengl_EXTBlendMinmax_glBlendEquationEXT(JNIEnv *__env, jclass clazz, jint mode) {
    glBlendEquationEXTPROC glBlendEquationEXT = (glBlendEquationEXTPROC)tlsGetFunction(1463);
    UNUSED_PARAM(clazz)
    glBlendEquationEXT(mode);
}
Beispiel #5
0
void Renderer_gl2::equMinIntensityProjection()
{
	if (! tryVolShader)
	{
		Renderer_gl1::equMinIntensityProjection();
		return;
	}
	glBlendEquationEXT(GL_MIN_EXT);//////////////////////////
}
Beispiel #6
0
void overlay(int texture, float alpha){
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	glBlendEquationEXT(GL_FUNC_REVERSE_SUBTRACT);
	glBlendFunc( GL_SRC_ALPHA, GL_ONE );
	glColor4f(1,1,1,alpha);
	glEnable(GL_BLEND);
	fullscreen_image(texture);
	glPopAttrib();
}
Beispiel #7
0
void RecLoopRender::draw(){
    VideoFrame * bufferFrame = buffer->getNextVideoFrame();
    VideoFrame * liveFrame   = live->getNextVideoFrame();
    if(bufferFrame!=NULL && liveFrame!=NULL){
        if(!imageAllocated){
            image.allocate(liveFrame->w,liveFrame->h,OF_IMAGE_COLOR);
            imageAllocated=true;
        }

        if(!bufferFrame->isTexAllocated())
            bufferFrame->update(recLoopVoidArgs);
        if(!liveFrame->isTexAllocated())
            liveFrame->update(recLoopVoidArgs);

        ofEnableAlphaBlending();
        ofSetColor(tintR,tintG,tintB,alpha);
        if(minmaxBlend)
            glBlendEquationEXT(GL_MAX);
        else
            glBlendEquationEXT(GL_MIN);

        bufferFrame->getTexture()->draw(0,0);
        liveFrame->getTexture()->draw(0,0);

        image.grabScreen(0,0,liveFrame->w,liveFrame->h);

        //unsigned char * pixels = bufferFrame->getVideoFrame();

        //memcpy(pixels,image.getPixels(),liveFrame->w*liveFrame->h*3*sizeof(unsigned char));

        bufferFrame->getTexture()->loadData(image.getPixels(),liveFrame->w,liveFrame->h,GL_RGB);

        liveFrame->release();

        //bufferFrame->setTexAllocated(false);
        //bufferFrame->update();

        bufferFrame->release();

        ofDisableAlphaBlending();
        glBlendEquationEXT(GL_FUNC_ADD);

    }
}
Beispiel #8
0
void Renderer_gl2::equAlphaBlendingProjection()
{
	if (! tryVolShader)
	{
		Renderer_gl1::equAlphaBlendingProjection();
		return;
	}
	glBlendEquationEXT(GL_FUNC_ADD_EXT);/////////////////////
	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);	// alpha multiplied in shader
}
 inline void VL_glBlendEquation(GLenum mode)
 {
   if (glBlendEquation)
     glBlendEquation(mode);
   else
   if (glBlendEquationEXT)
     glBlendEquationEXT(mode);
   else
     VL_UNSUPPORTED_FUNC();
 }
Beispiel #10
0
void Renderer_gl2::equCrossSection()
{
	if (! tryVolShader)
	{
		Renderer_gl1::equCrossSection();
		return;
	}
	glBlendEquationEXT(GL_FUNC_ADD_EXT);/////////////////////
	glBlendColorEXT(1, 1, 1, 1-CSbeta);
	glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA); // constant Alpha
}
    void GLStateCacheManagerImp::setBlendEquation(GLenum eq)
    {
        if(mBlendEquationRGB != eq || mBlendEquationAlpha != eq)
        {
            mBlendEquationRGB = eq;
            mBlendEquationAlpha = eq;

            if(GLEW_VERSION_1_4 || GLEW_ARB_imaging)
            {
                glBlendEquation(eq);
            }
            else if(GLEW_EXT_blend_minmax && (eq == GL_MIN || eq == GL_MAX))
            {
                glBlendEquationEXT(eq);
            }
        }
    }
Beispiel #12
0
/* allegro_gl_set_blender_mode (GFX_DRIVER vtable entry):
 * Sets the blending mode. Same implementation to all GFX vtables.
 */
void allegro_gl_set_blender_mode(int mode, int r, int g, int b, int a) {
	__allegro_gl_blit_operation = AGL_OP_BLEND;
	/* These blenders do not need any special extensions. 
	 * We specify only pixel arithmetic here. Blend equation and blend
	 * color (if available) are reset to defualt later.*/
	switch (mode) {
		case blender_mode_none:
			glBlendFunc(GL_ONE, GL_ZERO);
		break;
		case blender_mode_alpha:
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		break;
		case blender_mode_invert:
			glLogicOp(GL_COPY_INVERTED);
			__allegro_gl_blit_operation = AGL_OP_LOGIC_OP;
		break;
		case blender_mode_multiply:
			glBlendFunc(GL_DST_COLOR, GL_ZERO);
		break;
	}
	
	if (allegro_gl_opengl_version() >= 1.4 ||
	   (allegro_gl_opengl_version() >= 1.2 &&
		allegro_gl_is_extension_supported("GL_ARB_imaging"))) {
		/* We're running a recent version of OpenGL and everything needed is here. */
		
		glBlendColor(r / 255.f, g / 255.f, b / 255.f, a / 255.f);

		switch (mode) {
			case blender_mode_none:
				glBlendEquation(GL_FUNC_ADD);
			break;
			case blender_mode_alpha:
				glBlendEquation(GL_FUNC_ADD);
			break;
			case blender_mode_trans:
				glBlendEquation(GL_FUNC_ADD);
				glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA);
			break;
			case blender_mode_add:
				glBlendEquation(GL_FUNC_ADD);
				glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE);
			break;
			case blender_mode_burn:
				glBlendEquation(GL_FUNC_SUBTRACT);
				glBlendFunc(GL_ONE, GL_CONSTANT_ALPHA);
			break;
			case blender_mode_dodge:
				glBlendEquation(GL_FUNC_ADD);
				glBlendFunc(GL_ONE, GL_CONSTANT_ALPHA);
			break;
			case blender_mode_multiply:
				glBlendEquation(GL_FUNC_ADD);
			break;
		}

		return;
	}
	
	/* Check for presence of glBlendColor() and special parameters to
	 * glBlendFunc(). */
	if (allegro_gl_is_extension_supported("GL_EXT_blend_color")) {
		glBlendColorEXT(r / 255.f, g / 255.f, b / 255.f, a / 255.f);

		switch (mode) {
			case blender_mode_trans:
				glBlendFunc(GL_CONSTANT_ALPHA_EXT, GL_ONE_MINUS_CONSTANT_ALPHA_EXT);
			break;
			case blender_mode_add:
				glBlendFunc(GL_CONSTANT_ALPHA_EXT, GL_ONE);
			break;
			case blender_mode_burn:
				glBlendFunc(GL_ONE, GL_CONSTANT_ALPHA_EXT);
			break;
			case blender_mode_dodge:
				glBlendFunc(GL_ONE, GL_CONSTANT_ALPHA_EXT);
			break;
		}
	}
	else if (mode == blender_mode_trans ||
			 mode == blender_mode_add ||
			 mode == blender_mode_burn ||
			 mode == blender_mode_dodge) {
		/* glBlendColor() is not available and it is needed by the selected
		 * bledner. Bail out.*/
		return;
	}

	/* Check for presence of glBlendEquation(). */
	if (allegro_gl_is_extension_supported("GL_EXT_blend_minmax")) {
		switch (mode) {
			case blender_mode_none:
				glBlendEquationEXT(GL_FUNC_ADD_EXT);
			break;
			case blender_mode_alpha:
				glBlendEquationEXT(GL_FUNC_ADD_EXT);
			break;
			case blender_mode_trans:
				glBlendEquationEXT(GL_FUNC_ADD_EXT);
			break;
			case blender_mode_add:
				glBlendEquationEXT(GL_FUNC_ADD_EXT);
			break;
			case blender_mode_dodge:
				glBlendEquationEXT(GL_FUNC_ADD_EXT);
			break;
			case blender_mode_multiply:
				glBlendEquationEXT(GL_FUNC_ADD_EXT);
			break;
			case blender_mode_burn:
				if (allegro_gl_is_extension_supported("GL_EXT_blend_subtract")) {
					glBlendEquationEXT(GL_FUNC_SUBTRACT_EXT);
				}
				else {
					/* GL_FUNC_SUBTRACT is not supported and it is needed by the
					 * selected blender. Bail out. */
					return;
				}
			break;
		}
	}
}
Beispiel #13
0
static void Draw(void)
{
    int i;

    glDisable(GL_BLEND);
    if (supportlogops & 2)
       glDisable(GL_COLOR_LOGIC_OP);

    (dithering) ? glEnable(GL_DITHER) : glDisable(GL_DITHER);

    glClearColor(0.5, 0.6, 0.1, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);

    /* Draw background prims */
    glColor3f(0.1, 0.1, 1.0);
    glBegin(GL_TRIANGLES);
        glVertex2i(5, 5);
        glVertex2i(130, 50);
        glVertex2i(100,  300);
    glEnd();
    glColor3f(0.5, 0.2, 0.9);
    glBegin(GL_TRIANGLES);
        glVertex2i(200, 100);
        glVertex2i(330, 50);
        glVertex2i(340,  400);
    glEnd();

    glEnable(GL_BLEND);
    if (!use11ops)
       glBlendEquationEXT(GL_LOGIC_OP);
    else
       glEnable(GL_COLOR_LOGIC_OP);
    glLogicOp(GL_XOR);

    /* Draw a set of rectangles across the window */
    glColor3f(0.9, 0.2, 0.8);
    for(i = 0; i < 400; i+=60) {
        glBegin(GL_POLYGON);
            glVertex2i(i, 100);
            glVertex2i(i+50, 100);
            glVertex2i(i+50, 200);
            glVertex2i(i, 200);
        glEnd();
    }
    glFlush();   /* Added by Brian Paul */
#ifndef _WIN32
    sleep(2);
#endif

    /* Redraw  the rectangles, which should erase them */
    for(i = 0; i < 400; i+=60) {
        glBegin(GL_POLYGON);
            glVertex2i(i, 100);
            glVertex2i(i+50, 100);
            glVertex2i(i+50, 200);
            glVertex2i(i, 200);
        glEnd();
    }
    glFlush();


    if (doubleBuffer) {
	glutSwapBuffers();
    }
}
Beispiel #14
0
int main(){
	MSG message;
	HSTREAM stream = 0;
	object *room;
	object *sphere;
	object *sphere_copy;
	rtt_target *rendertarget;

	rtt_target *fucking_shit;

	int loading;
	int bjork_texture;
	int yo_plus;
	int carlb;
	int i;
	int veldig_kule;
	int greets;
	int mothafuckas;

	vector particles[PARTICLE_COUNT];
	make_random_particles(particles, PARTICLE_COUNT, 200);

	if(!mumps_open("CARL B!!!!1",WIDTH,HEIGHT,32,32,-1,FULLSCREEN)) error("kunne ikke lage bartevindu");
	if(!init_extensions()){
		mumps_close();
		error("kunne ikke bruke fet opengl-extension");
	}
	if (!BASS_Init(-1, 44100, 0, 0, 0)) {
		mumps_close();
		error("kunne ikke åpne fet lyd");
	}
	stream = BASS_StreamCreateFile(FALSE, "data/uglespy.ogg", 0, 0, BASS_MP3_SETPOS | BASS_STREAM_PRESCAN | 0);
	if (!stream) {
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fet lyd 2.0");
	}

	loading = load_texture("loading.jpg", FALSE);
	if(loading==-1){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett bilde");
	}

	glClearColor(0,0,0,0);
	glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
	fullscreen_image(loading);
	glFlush();
	mumps_update();


	room = load_object("cylinder01.kro");
	if(!room){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett objekt");
	}

	sphere = load_object("sphere01.kro");
	if(!sphere){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett objekt");
	}
	sphere_copy = copy_object(sphere);

	bjork_texture = load_texture("bjork.jpg", FALSE);
	if(bjork_texture==-1){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett bilde");
	}
	yo_plus = load_texture("yo_plus.jpg", FALSE);
	if(yo_plus==-1){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett bilde");
	}
	carlb = load_texture("carlb.jpg", FALSE);
	if(carlb==-1){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett bilde");
	}
	veldig_kule = load_texture("veldig_kule.jpg", FALSE);
	if(veldig_kule==-1){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett bilde");
	}
	greets = load_texture("greets.jpg", FALSE);
	if(greets==-1){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett bilde");
	}
	mothafuckas = load_texture("mothefuckas.jpg", FALSE);
	if(mothafuckas==-1){
		BASS_StreamFree(stream);
		BASS_Free();
		mumps_close();
		error("kunne ikke åpne fett bilde");
	}

	rendertarget = init_rtt(512,256,(float)WIDTH/(float)HEIGHT, FALSE, FALSE);
	fucking_shit = init_rtt(512,256,(float)WIDTH/(float)HEIGHT, FALSE, TRUE);
	init_blur(256,256);

	glEnable(GL_NORMALIZE);
	
	BASS_Start();
	BASS_ChannelPlay(stream, FALSE);

	do {
		QWORD pos = BASS_ChannelGetPosition(stream, BASS_POS_BYTE);
		double time = BASS_ChannelBytes2Seconds(stream, pos);

		glViewport(0,0,mumps_width,mumps_height);

		if(time<25.55f){
			glClearColor(1,1,1,0);
			glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
			glMatrixMode(GL_TEXTURE);
			glLoadIdentity();
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();

			gluPerspective(120, ASPECT, 1.f, 500);

			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();

			glFogi(GL_FOG_MODE, GL_EXP2);
			glFogfv(GL_FOG_COLOR,black_color);
			glFogf(GL_FOG_DENSITY, 0.02f);
			glEnable(GL_FOG);

			set_camera(
				vector_make( // pos
					(float)sin(time*0.1f)*50,
					(float)sin(time*1.2f*0.1f+1)*50,
					(float)cos(sin(time*0.1f)-time*0.1f)*50
				),
				vector_make( // look_at
					0, 0, 0
				),
				0
			);

			draw_particles(particles,PARTICLE_COUNT,yo_plus, (float)15);

			if(time<2){
				float alpha = 1.f-time*0.5f;
				glPushAttrib(GL_ALL_ATTRIB_BITS);
				glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

				glColor4f(1,1,1, alpha );
				glEnable(GL_BLEND);
				fullscreen_image(loading);
				glPopAttrib();

			}

			if(time>17.5f){
				float alpha = (time-17.5);

				glPushAttrib(GL_ALL_ATTRIB_BITS);
				glBlendEquationEXT(GL_FUNC_REVERSE_SUBTRACT);
				glBlendFunc( GL_SRC_ALPHA, GL_ONE );

				glColor4f(1,1,1, alpha );
				glEnable(GL_BLEND);
				fullscreen_image(carlb);
				glPopAttrib();
			}
		}else if(time<51.0f){
			float flash = 1.f-(time-25.55f);
			glClearColor(1,1,1,0);
			glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
			glMatrixMode(GL_TEXTURE);
			glLoadIdentity();
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			gluPerspective(90, ASPECT, 1.f, 500);
			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();

			glDisable(GL_FOG);


			gluLookAt(
				sin(time*0.1f)*90,-50,cos(time*0.1f)*90,
				0,-30,0,

				0,1,0
				);

			start_rtt(rendertarget);

			set_light(0, (float)sin(time)*50,0,(float)cos(time)*50,TRUE);
			set_light(1, (float)sin(time+1)*50,0,(float)cos(time+1)*50,TRUE);

			glEnable(GL_LIGHTING);
			glEnable(GL_DEPTH_TEST);

			glPushMatrix();
			glTranslatef(100,0,-100);
			draw_object(room);
			glPopMatrix();

			glPushMatrix();
			glTranslatef(0,-30,0);
			glScalef(0.7f,0.7f,0.7f);
			glRotatef(time*15,1,0,1);
			glRotatef(time*15,1,0,0);
			glRotatef(time*15.2f,0,1,0);

			glRotatef(time*15,0,0,1);
			glRotatef(time*25,1,0,0);
			glRotatef(time*15.2f,0,1,0);

			blob_distort(sphere, sphere_copy, vector_make((float)sin(time),time,-time), vector_make(
				(float)(1+sin(time))*0.1f,
				(float)(1+sin(time))*0.1f,
				(float)(1+sin(time))*0.1f
				),vector_make(0.3f,0.3f,0.3f) );
			draw_object(sphere_copy);
			glPopMatrix();

			end_rtt(rendertarget);

			i = blur((float)sin(time*0.3f)*0.3f, 0.1f+(1+(float)sin(time*0.1f))*0.2f, 0.2f, FALSE, rendertarget->texture);

			fullscreen_image(i);

			glEnable(GL_COLOR_MATERIAL);
			glColor4f(1,1,1, (1+(float)sin(time*0.5f))*0.3f );
			glBlendFunc( GL_SRC_ALPHA, GL_ONE );
			glEnable(GL_BLEND);
			fullscreen_image(bjork_texture);
			glDisable(GL_BLEND);


			if(time>38.35f){
				flash = 1.f-(time-38.4f);
				if(time>44.75f){
					flash = 1.f-(time-44.75f);
				}
			}

			if(flash<0) flash = 0;
			superflash(flash);

			if(time>38.35f){
				overlay(veldig_kule, 1);
			}
		}else if(time<(60+16.8f)){
			float flash = (1.f-(time-51.f));
			float flash2 = sin(-(3.1415f/2)+(time-51.f)*(117.5f/60.f)*8);
			if(flash<0) flash = 0;

			flash *= flash;


			flash2 *= (1+flash2)*0.5f;
			flash2 *= 20;

			start_rtt(fucking_shit);
			draw_dilldallscene(room, sphere, sphere_copy,time,flash,flash2);
			end_rtt(fucking_shit);

			glClearColor(0,0,0,0);
			glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

			draw_dilldallscene(room, sphere, sphere_copy,time,flash,flash2);

			glLoadIdentity();

			glEnable(GL_COLOR_MATERIAL);
			glColor4f(1,1,1, 0.5+(1+(float)sin(time*0.5f))*0.5f );
			glBlendFunc( GL_SRC_ALPHA, GL_ONE );
			glEnable(GL_BLEND);
			fullscreen_image_flip(fucking_shit->texture,1);
			fullscreen_image_flip(fucking_shit->texture,2);
			fullscreen_image_flip(fucking_shit->texture,3);
			glDisable(GL_BLEND);

			fuss(50,time, 1, 1, 0.1f);
			if(time>(60+3.9f)){
				flash=(1.f-(time-(60+3.9f)));
				overlay(greets, 1);
			}
			superflash(flash);
		}else{
			float flash = (1.f-(time-(60+16.8f)));
			fullscreen_image(mothafuckas);
			superflash(flash);
			if(time>(60+23.f)){
				float flash = (time-(60+23.f));
				superflash2(flash*0.5f);
			}
		}
		glFlush();
		mumps_update();

		if(time>60+30) PostQuitMessage(0);

		while(PeekMessage(&message,NULL,0,0,PM_REMOVE)){
			TranslateMessage(&message);
			DispatchMessage(&message);
		    if(message.message == WM_QUIT) break;
		}
	}while(message.message!=WM_QUIT && !GetAsyncKeyState(VK_ESCAPE));
	BASS_StreamFree(stream);
	BASS_Free();
	mumps_close();
	MessageBox(NULL,"Frigi minnet ditt sjøl, taper","In your face",MB_OK);
	return 0;
}
Beispiel #15
0
/*
 * Called when window needs to be redrawn 
 */
void 
redraw(void)
{
    int i, x, y;

    if (viewImage) {
	glReadBuffer(GL_FRONT);
	glDrawBuffer(GL_FRONT);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, (GLubyte *) img);
    } else if (!drawEdges) {
	glDrawBuffer(useStrokes ? GL_BACK : GL_FRONT);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	/*
	 * Just draw the voronoi regions 
	 */
	for (i = 0; i < numPoints; i++) {
	    glPushMatrix();
	    glTranslatef(points[i].x, points[i].y, 0.f);
	    glColor3ub(points[i].r, points[i].g, points[i].b);
	    glCallList(1);
	    glColor3f(0.f, 0.f, 0.f);
	    glPopMatrix();
	}

	if (useStrokes)
	    glutSwapBuffers();
    } else {
	glClear(GL_COLOR_BUFFER_BIT | GL_ACCUM_BUFFER_BIT);
	glReadBuffer(GL_BACK);
	glDrawBuffer(GL_BACK);

	glutSetWindowTitle("Voronoi art (working...)");
	glutSetCursor(GLUT_CURSOR_WAIT);
	for (y = 0; y < 3; y++)
	    for (x = 0; x < 3; x++) {
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glPushMatrix();
		glTranslatef(x - 1, y - 1, 0.0);

		for (i = 0; i < numPoints; i++) {
		    glPushMatrix();
		    glTranslatef(points[i].x, points[i].y, 0.f);
		    glColor3ub(points[i].r, points[i].g, points[i].b);
		    glCallList(1);
		    glPopMatrix();
		}
		glPopMatrix();

		glAccum(GL_ACCUM, edgeKernel[3 * y + x]);
	    }

	glAccum(GL_RETURN, 0.5);
	glutSetWindowTitle("Voronoi art");
	glutSetCursor(GLUT_CURSOR_INHERIT);

	/*
	 * Convert to grayscale 
	 */
	glMatrixMode(GL_COLOR);
	glLoadMatrixf(sumMatrix);
	glCopyPixels(0, 0, w, h, GL_COLOR);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);

	/*
	 * Threshold 
	 */
	glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
	glCopyPixels(0, 0, w, h, GL_COLOR);
	glPixelTransferi(GL_MAP_COLOR, GL_FALSE);

	/*
	 * Draw the voronoi regions in the front buffer 
	 */
	glDrawBuffer(GL_FRONT);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	for (i = 0; i < numPoints; i++) {
	    glPushMatrix();
	    glTranslatef(points[i].x, points[i].y, 0.f);
	    glColor3ub(points[i].r, points[i].g, points[i].b);
	    glCallList(1);
	    glColor3f(0.f, 0.f, 0.f);
	    glPopMatrix();
	}

	/*
	 * Blend in the edge lines 
	 */
	glClear(GL_DEPTH_BUFFER_BIT);
	glBlendEquationEXT(GL_MIN_EXT);
	glEnable(GL_BLEND);
	glCopyPixels(0, 0, w, h, GL_COLOR);
	glDisable(GL_BLEND);
    }

    glFlush();
}