Click here to Skip to main content
15,891,529 members
Articles / Desktop Programming / MFC

PicZoom: A Photo Viewer Created in OpenGL

Rate me:
Please Sign up or sign in to vote.
4.86/5 (63 votes)
16 Feb 2011CPOL16 min read 160.7K   11.6K   150  
PicZoom: A Photo Viewer created in OpenGL
#include "StdAfx.h"
#include "GLCircle.h"
#include "math.h"
#include "GL\Gl.h"

const float DEG2RAD = 3.14159/180.0;

GLCircle::GLCircle(void)
{
    m_nLineWidth = 1;
    m_nStartAngle = 0;
    m_nX = 0;
    m_nY = 0;
    m_nEndAngle = 360;
    m_nRadius = 10;
    m_fTransparency = 1.0;
}

GLCircle::~GLCircle(void)
{

}

void GLCircle::SetRadius( const int nRadius_i )
{
    m_nRadius = nRadius_i;
}

void GLCircle::SetPosition( const int nX_i, const int nY_i )
{
    m_nX = nX_i;
    m_nY = nY_i;
}
void GLCircle::SetAngle( const int nStartAngle_i, const int nEndAngle_i )
{
    m_nStartAngle = nStartAngle_i;
    m_nEndAngle = nEndAngle_i;
}
void GLCircle::SetColor( const float fRed_i, const float fGreen_i, const float fBlue_i )
{
    m_Color = GLColor( fRed_i, fGreen_i, fBlue_i );
}
void GLCircle::SetTransparency( const float fTransparency_i )
{
    m_fTransparency = fTransparency_i;
}

void GLCircle::SetLineWidth( const int nWidth_i )
{
    m_nLineWidth = nWidth_i;
}

void GLCircle::Draw()
{
    glMatrixMode( GL_MODELVIEW );
    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glLineWidth( m_nLineWidth );
    glPushMatrix();
    glTranslatef( m_nX, m_nY, 0 );
    glColor4f( m_Color.m_fRed, m_Color.m_fGreen, m_Color.m_fBlue , m_fTransparency );
    glBegin( GL_LINE_STRIP );
    for (int i=m_nStartAngle; i <= m_nEndAngle; i++)
    {
        float degInRad = i*DEG2RAD;
        glVertex2f(cos(degInRad)*m_nRadius,sin(degInRad)*m_nRadius);
    }
    glEnd();
    glColor3f( 1.0, 1.0, 1.0 );
    glPopMatrix();
    glDisable( GL_LINE_SMOOTH );
    glDisable( GL_POLYGON_SMOOTH );
    glDisable( GL_BLEND );
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions