Click here to Skip to main content
15,912,205 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: implicit cast between pointers [modified] Pin
Aescleal16-Jun-10 22:37
Aescleal16-Jun-10 22:37 
QuestionPointer and Reference Pin
T.RATHA KRISHNAN16-Jun-10 2:51
T.RATHA KRISHNAN16-Jun-10 2:51 
AnswerRe: Pointer and Reference Pin
Cedric Moonen16-Jun-10 2:54
Cedric Moonen16-Jun-10 2:54 
QuestionRe: Pointer and Reference Pin
T.RATHA KRISHNAN16-Jun-10 3:05
T.RATHA KRISHNAN16-Jun-10 3:05 
AnswerRe: Pointer and Reference Pin
Cedric Moonen16-Jun-10 3:08
Cedric Moonen16-Jun-10 3:08 
QuestionReflecting programmatically changed RTL reading order on CEdit control Pin
katreddi.lakshmi16-Jun-10 2:03
katreddi.lakshmi16-Jun-10 2:03 
AnswerRe: Reflecting programmatically changed RTL reading order on CEdit control Pin
katreddi.lakshmi20-Jun-10 20:19
katreddi.lakshmi20-Jun-10 20:19 
Questionhow to load texture on a circle in open GL Pin
nearest15-Jun-10 22:27
nearest15-Jun-10 22:27 
i m working with open GL enviroment in visual C++. i have tried to load texture on circle. it is hapening but texture is copied again and again on a circle. i know that problum is in 'glTexCoord2d()'func. i couldnt get the exact coordinate of texture. can any ony help me?
here is the source code
#include <GL/glut.h>
#include <GL/gl.h>
#include <windows.h>
#include <math.h>
#include<stdio.h>
#include<iostream.h>
double frame;
float rot = 0;


const GLfloat DEG2RAD = 3.14159/180;
GLuint texture; 
//const GLfloat DEG2RAD = 3.14159/180;
int refreshMillis = 10000; 

GLuint LoadTexture( const char * filename, int width, int height )
{
    GLuint texture;
    unsigned char * data;
    FILE * file;

    //The following code will read in our RAW file
    file = fopen( filename, "rb" );
    if ( file == NULL ) 
		return 0;
    data = (unsigned char *)malloc( width * height * 3 );
    fread( data, width * height * 3, 1, file );
    fclose( file );

    glGenTextures( 1, &texture ); //generate the texture with the loaded data
    glBindTexture( GL_TEXTURE_2D, texture ); //bind the texture to it’s array
   glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); //set texture environment parameters

    //here we are setting what textures to use and when. The MIN filter is which quality to show
    //when the texture is near the view, and the MAG filter is which quality to show when the texture
    //is far from the view.

    //The qualities are (in order from worst to best)
    //GL_NEAREST
    //GL_LINEAR
    //GL_LINEAR_MIPMAP_NEAREST
    //GL_LINEAR_MIPMAP_LINEAR

    //And if you go and use extensions, you can use Anisotropic filtering textures which are of an
    //even better quality, but this will do for now.
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR );

    //Here we are setting the parameter to repeat the texture instead of clamping the texture
    //to the edge of our shape. 
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

    //Generate the texture with mipmaps
    gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height,GL_RGB, GL_UNSIGNED_BYTE, data ); 
    free( data ); //free the texture
    return texture; //return whether it was successfull
}

void FreeTexture( GLuint texture )
{
  glDeleteTextures( 1, &texture ); 
}


 

void drawEllipse1(void)
{
GLint i;
GLfloat xradius=2;
GLfloat yradius=2; 
//glColor3f(1,0,0);
  
 
 
glBegin(GL_POLYGON); 
 
   for (i=0; i < 360; i++)
   {

      //convert degrees into radians
      float degInRad = i*DEG2RAD; 
	  glTexCoord2d(-cos (degInRad) *xradius, - sin (degInRad) *yradius); 
      glVertex2f ( cos (degInRad) *xradius,  sin (degInRad) *yradius);
   }
 
glEnd();
}



void display()
{
	glClearColor(0.0, 1.0, 1.0, 0);
	
    glClear(GL_COLOR_BUFFER_BIT);

     glLoadIdentity ();

   
     glPushMatrix() ;
	 glEnable( GL_TEXTURE_2D );
     glTranslatef(0,0,-17) ;

	  drawEllipse1() ;
	 glBindTexture( GL_TEXTURE_2D, texture);
     
	 glDisable( GL_TEXTURE_2D );
     glPopMatrix() ;
	


    
    glutSwapBuffers();
   rot=rot+1.4;
  
 
}

void init (void) 
{
	 
	texture = LoadTexture( "smiley1.raw", 640, 480);

    
}

void reshape (int w, int h) {
    glViewport (0, 0, (GLsizei)w, (GLsizei)h);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
    glMatrixMode (GL_MODELVIEW);
}

int main(int argc,char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE);
	 glutInitWindowSize (640, 480);
	 glutInitWindowPosition (100, 100);
	glutCreateWindow("ellipse");
    init();
	glutDisplayFunc(display);//CHANGED
    glutIdleFunc (display);
	 glutReshapeFunc (reshape);
	glutMainLoop();
	return 0;
}

AnswerRe: how to load texture on a circle in open GL Pin
Cedric Moonen15-Jun-10 23:31
Cedric Moonen15-Jun-10 23:31 
AnswerRe: how to load texture on a circle in open GL Pin
Cedric Moonen15-Jun-10 23:54
Cedric Moonen15-Jun-10 23:54 
AnswerRe: how to load texture on a circle in open GL Pin
Rick York16-Jun-10 16:46
mveRick York16-Jun-10 16:46 
Questiontoggle bits in a variable Pin
rupeshkp72815-Jun-10 21:29
rupeshkp72815-Jun-10 21:29 
AnswerRe: toggle bits in a variable Pin
OriginalGriff15-Jun-10 21:40
mveOriginalGriff15-Jun-10 21:40 
AnswerRe: toggle bits in a variable Pin
Cedric Moonen15-Jun-10 21:40
Cedric Moonen15-Jun-10 21:40 
QuestionLNK 2019 Pin
T.RATHA KRISHNAN15-Jun-10 21:21
T.RATHA KRISHNAN15-Jun-10 21:21 
AnswerRe: LNK 2019 Pin
Richard MacCutchan15-Jun-10 21:47
mveRichard MacCutchan15-Jun-10 21:47 
AnswerRe: LNK 2019 Pin
Aescleal16-Jun-10 7:02
Aescleal16-Jun-10 7:02 
QuestionIntegration in MFC Pin
Sakhalean15-Jun-10 21:18
Sakhalean15-Jun-10 21:18 
AnswerRe: Integration in MFC Pin
Cedric Moonen15-Jun-10 21:59
Cedric Moonen15-Jun-10 21:59 
GeneralRe: Integration in MFC Pin
Sakhalean15-Jun-10 23:05
Sakhalean15-Jun-10 23:05 
AnswerRe: Integration in MFC Pin
goorley15-Jun-10 22:01
goorley15-Jun-10 22:01 
Questionstd string mid function Pin
gmallax15-Jun-10 21:17
gmallax15-Jun-10 21:17 
AnswerRe: std string mid function Pin
Nuri Ismail15-Jun-10 21:25
Nuri Ismail15-Jun-10 21:25 
QuestionTeeChart Pro AX v6 Pin
eyalle15-Jun-10 20:19
eyalle15-Jun-10 20:19 
QuestionRead File Pin
MsmVc15-Jun-10 19:49
MsmVc15-Jun-10 19:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.