The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to insert JPEG on each side of the cube using openGl Ravikishore Ubuntu 1 10-26-2009 08:53 AM
i am new to opengl , how to work opengl in ubuntu Ravikishore Ubuntu 7 09-03-2009 11:45 AM
How to Merge / combine / join / paste 2 text files side-by-side cajunfries Shell Programming and Scripting 3 04-27-2009 08:25 PM
Script to place selected columns from a group of files side by side in a new file ks_reddy Shell Programming and Scripting 8 02-12-2009 12:09 PM
How to print two sql query outputs side by side in excel prasee Shell Programming and Scripting 6 09-08-2007 03:20 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-26-2009
Ravikishore Ravikishore is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 31
Exclamation How to insert JPEG on each side of the cube using openGL in C

Hi,

how to insert JPEG on each side of the cube using OpenGL in C language..
i have a program for cube..

guide me ,,,
any answer will valuable..
  #2 (permalink)  
Old 10-26-2009
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
Please read the The UNIX and Linux Forums - FAQ

and do not multiple/cross post.
how to insert JPEG on each side of the cube using openGl

What have you tried so far...where is it failing. Posting code is more likely to get you an answer than an open question.
  #3 (permalink)  
Old 10-26-2009
Ravikishore Ravikishore is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 31
Exclamation How to insert JPEG on each side of the cube using openGL

Hi,

The below code is working and it generate a cube which is rotating...

i need to insert JPEG on each side of the rotating cube...

Code:
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>

#define VIEWING_DISTANCE_MIN  3.0
#define TEXTURE_ID_CUBE 1

static struct timeval last_idle_time;
static GLfloat g_fTeapotAngle = 0.0;
static GLfloat g_fTeapotAngle2 = 0.0;

//static DWORD last_idle_time;

static GLfloat g_fViewDistance = 3 * VIEWING_DISTANCE_MIN;
static float g_lightPos[4] = { 10, 10, -100, 1 };

static GLfloat g_nearPlane = 1;
static GLfloat g_farPlane = 1000;
static int g_Width = 600;
static int g_Height = 600;

void DrawCubeFace(float fSize)
{
  fSize /=1.0;
  glBegin(GL_QUADS);
  glVertex3f(-fSize, -fSize, fSize);    glTexCoord2f (0, 0);
  glVertex3f(fSize, -fSize, fSize);     glTexCoord2f (1, 0);
  glVertex3f(fSize, fSize, fSize);      glTexCoord2f (1, 1);
  glVertex3f(-fSize, fSize, fSize);     glTexCoord2f (0, 1);
  glEnd();
}

void DrawCubeWithTextureCoords (float fSize)
{
  glPushMatrix();
  DrawCubeFace (fSize);
  glRotatef (90, 1, 0, 0);
  DrawCubeFace (fSize);
  glRotatef (90, 1, 0, 0);
  DrawCubeFace (fSize);
  glRotatef (90, 1, 0, 0);
  DrawCubeFace (fSize);
  glRotatef (90, 0, 1, 0);
  DrawCubeFace (fSize);
  glRotatef (180, 0, 1, 0);
  DrawCubeFace (fSize);
  glPopMatrix();
}

 void RenderObjects(void)
{
  float colorBronzeDiff[4] = { 0.9, 0.9, 0.0, 1.0 };
  float colorBronzeSpec[4] = { 1.0, 1.0, 0.9, 1.0 };
  float colorBlue[4]       = { 0.0, 0.9, 1.0, 1.0 };
  float colorNone[4]       = { 0.0, 0.0, 0.0, 0.0 };

  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
 glRotatef(25, 1, 0, 0);
  glRotatef(45, 0, 1, 0);
glRotatef(g_fTeapotAngle, 0, 0, 1);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, colorBlue);
  glMaterialfv(GL_FRONT, GL_SPECULAR, colorNone);
           glColor4fv(colorBlue);
        glBindTexture(GL_TEXTURE_2D, TEXTURE_ID_CUBE);
        DrawCubeWithTextureCoords(1.0);
            glPushMatrix();
 //        glTranslatef(2, 0, 0);
 glRotatef(g_fTeapotAngle2, 1, 1, 0);
      glMaterialfv(GL_FRONT, GL_DIFFUSE, colorBronzeDiff);
   glMaterialfv(GL_FRONT, GL_SPECULAR, colorBronzeSpec);
     glMaterialf(GL_FRONT, GL_SHININESS, 50.0);
               glColor4fv(colorBronzeDiff);
//    glutSolidCone(0.3f, 0.8f,5, 4);
        glBindTexture(GL_TEXTURE_2D, 0);
    glPopMatrix();
    glPopMatrix();
    }



void display(void)
{

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glLoadIdentity();
   gluLookAt(0, 0, -g_fViewDistance, 0, 0, -1, 0, 1, 0);


   glLightfv(GL_LIGHT0, GL_POSITION, g_lightPos);


   RenderObjects();


   glutSwapBuffers();
}

void reshape(GLint width, GLint height)
{
   g_Width = width;
   g_Height = height;

   glViewport(0, 0, g_Width, g_Height);
   glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
gluPerspective(65.0, (float)g_Width / g_Height, g_nearPlane, g_farPlane);
   glMatrixMode(GL_MODELVIEW);
}

 void AnimateScene(void)
{ float dt;

#ifdef _WIN32
  DWORD time_now;
  time_now = GetTickCount();
  dt = (float) (time_now - last_idle_time) / 1000.0;
#else

  struct timeval time_now;
  gettimeofday(&time_now, NULL);
  dt = (float)(time_now.tv_sec  - last_idle_time.tv_sec) +
  1.0e-6*(time_now.tv_usec - last_idle_time.tv_usec);
#endif


 g_fTeapotAngle += dt * 30.0;
 g_fTeapotAngle2 += dt * 100.0;


  last_idle_time = time_now;

glutPostRedisplay();
}

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

  glutInit (&argc, argv);
         glutInitWindowSize (g_Width, g_Height);
  glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  glutCreateWindow ("RAVI");


//  InitGraphics();


    glutDisplayFunc (display);
      glutReshapeFunc (reshape);
//        glutKeyboardFunc (Keyboard);
        //          glutMouseFunc (MouseButton);
  //          glutMotionFunc (MouseMotion);
              glutIdleFunc (AnimateScene);

glutAttachMenu (GLUT_RIGHT_BUTTON);


#ifdef _WIN32
  last_idle_time = GetTickCount();
#else
  gettimeofday (&last_idle_time, NULL);
#endif



  glutMainLoop ();

return 0;
}



This is the full code ....please guide me ...any answer is valuable...

Last edited by pludi; 10-26-2009 at 08:54 AM.. Reason: code tags, please...
  #4 (permalink)  
Old 10-26-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,949
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:02 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0