0% found this document useful (0 votes)
15 views3 pages

Algoritmo Antialiasing

The document describes an algorithm for antialiasing lines drawn in OpenGL. It defines functions to draw single pixels and lines between two points, calculating antialiased pixels above and below the line. Mouse click events allow selecting start and end points for a line, which is then drawn using the antialiased line drawing function. The main function initializes the OpenGL window and calls functions to clear the background and handle mouse input.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Algoritmo Antialiasing

The document describes an algorithm for antialiasing lines drawn in OpenGL. It defines functions to draw single pixels and lines between two points, calculating antialiased pixels above and below the line. Mouse click events allow selecting start and end points for a line, which is then drawn using the antialiased line drawing function. The main function initializes the OpenGL window and calls functions to clear the background and handle mouse input.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

DANIEL EDUARDO PEDROZA PEDRAZA

U6000459@UNIMILITAR.EDU.CO

ALGORITMO ANTIALIASING

#include "glut.h"
#include <math.h>

float ancho = 300, alto = 300;


int CX1, CX2, CY1, CY2;

void pintaPixel(int x, int y, int r, int v, int a){


glPointSize(1);
glBegin(GL_POINTS);
glColor3f(r, v, a);
glVertex2f(x, y);
glEnd();
}

void pintalinea(int CX1, int CY1, int CX2, int CY2) {


int DX, DY, x, y;
float m, b;
DX = CX2 - CX1;
DY = CY2 - CY1;
if (DX == 0)
{
if (CY1 <= CY2)
{
for (y = CY1; y <= CY2; y++)
{
pintaPixel(CX1, y, 1, 1, 1);
}
}
else
{
for (y = CY2; y <= CY1; y++)
{
pintaPixel(CX1, y, 1, 1, 1);
}
}
}
if (DY == 0)
{
if (CX1 <= CX2)
{
for (x = CX1; x <= CX2; x++)
{
pintaPixel(x, CY1, 1, 1, 1);
pintaPixel(x + 1, CY1, 1, 1, 1);
}
}
else
{
for (x = CX2; x <= CX1; x++)
{
pintaPixel(x, CY1, 1, 1, 1);
pintaPixel(x + 1, CY1, 1, 1, 1);
}
}
}
else
{
m = float(DY) / float(DX);
DANIEL EDUARDO PEDROZA PEDRAZA
U6000459@UNIMILITAR.EDU.CO

b = CY1 - (m*CX1);
if (abs(DX) >= abs(DY))
{
if (CX1 <= CX2)
{
for (x = CX1; x <= CX2; x++)
{
y = (m*x) + b;
pintaPixel(x, y, 1, 1, 1);
pintaPixel(x, y + 1, 0.5, 0.5, 0.5);
pintaPixel(x, y - 1, 0.5, 0.5, 0.5);
}
}
else
{
for (x = CX2; x <= CX1; x++)
{
y = (m*x) + b;
pintaPixel(x, y, 1, 1, 1);
pintaPixel(x, y + 1, 0.5, 0.5, 0.5);
pintaPixel(x, y - 1, 0.5, 0.5, 0.5);
}
}
}
else
{
if (CY1 <= CY2)
{
for (y = CY1; y <= CY2; y++)
{
x = (y - b) / m;
pintaPixel(x, y, 1, 1, 1);
pintaPixel(x+1, y, 0.5, 0.5, 0.5);
pintaPixel(x-1, y, 0.5, 0.5, 0.5);
}
}
else
{
for (y = CY2; y <= CY1; y++)
{
x = (y - b) / m;
pintaPixel(x, y, 1, 1, 1);
pintaPixel(x + 1, y, 0.5, 0.5, 0.5);
pintaPixel(x - 1, y, 0.5, 0.5, 0.5);
}
}
}
}
}

void raton(int btm, int state, int x, int y) {

if (state == GLUT_DOWN && btm == GLUT_RIGHT_BUTTON) {


CX1 = x - (ancho / 2);
CY1 = (alto / 2) - y;
pintaPixel(CX1, CY1, 1, 1, 1);
}
if (state == GLUT_DOWN && btm == GLUT_LEFT_BUTTON) {
CX2 = x - (ancho / 2);
CY2 = (alto / 2) - y;
pintaPixel(CX2, CY2, 1, 1, 1);
DANIEL EDUARDO PEDROZA PEDRAZA
U6000459@UNIMILITAR.EDU.CO

pintalinea(CX1, CY1, CX2, CY2);


}
glFlush();
}

void plano() {
for (float i = -(alto / 2); i < alto; i++) {
pintaPixel(0, i, 1, 1, 1);
}
for (float i = -(ancho / 2); i < ancho; i++) {
pintaPixel(i, 0, 1, 1, 1);
}
glFlush();
}

int main(int argc, char**argv) {


glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(ancho, alto);
glutCreateWindow("ANTIALIASING");
gluOrtho2D(-(ancho / 2), (ancho / 2), -(alto / 2), (alto / 2));
glClearColor(0, 0, 0, 0);
glutDisplayFunc(plano);
glutMouseFunc(raton);
glutMainLoop();
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy