How to insert JPEG on each side of the cube using openGL in C


 
Thread Tools Search this Thread
Top Forums Programming How to insert JPEG on each side of the cube using openGL in C
# 1  
Old 10-26-2009
Error 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  
Old 10-26-2009
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  
Old 10-26-2009
Error 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 09:54 AM.. Reason: code tags, please...
# 4  
Old 10-26-2009
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run 2 python scripts at the same time side by side on the same line?

Could I run 2 python scripts at the same time side by side output on the same line in this same format but with scripts? from itertools import izip_longest with open("file1") as textfile1, open("file2") as textfile2: for x, y in izip_longest(textfile1, textfile2, fillvalue=""): x =... (4 Replies)
Discussion started by: bigvito19
4 Replies

2. Shell Programming and Scripting

AWK to merge multiple files side by side

I have about 100s of files of type text in a known directory. I want to merge all files side by side. Number of lines in all the files will remain same. For example file1 contains cat dog File 2 contains rat mat Output file should be cat rat dog mat Using awk I was able to... (5 Replies)
Discussion started by: kanthrajgowda
5 Replies

3. Shell Programming and Scripting

printing 3 files side by side based on similar values in rows

Hi I'm trying to compare 3 or more files based on similar values and outputting them into 3 columns. For example: file1 ABC DEF GHI file2 DEF DER file3 ABC DER The output should come out like this file1 file2 file3 ABC ABC (4 Replies)
Discussion started by: zerofire123
4 Replies

4. Shell Programming and Scripting

Paste two file side by side together based on specific pattern match problem

Input file_1: P78811 P40108 O17861 Q6NTW1 P40986 Q6PBK1 P38264 Q6PBK1 Q9CZ49 Q1GZI0 Input file_2: (6 Replies)
Discussion started by: patrick87
6 Replies

5. Ubuntu

how to insert JPEG on each side of the cube using openGl

Hi all, i have the program to rotate the cube using openGL. i want to insert J PEG on each side of the rotating cube using openGL in C... please guide me,,any answer will appreciated.. (1 Reply)
Discussion started by: Ravikishore
1 Replies

6. Ubuntu

i am new to opengl , how to work opengl in ubuntu

Hi, i am new to opengl, how to work openGL in ubuntu ,, i am not getting which packages as to be install and how to install those packages. and how to work with small programs.. Please guide me ,,, it will appriceated ... (7 Replies)
Discussion started by: Ravikishore
7 Replies

7. Web Development

Cannot access Apache web server from Wan side, only Lan side.

I have installed WAMPSERVER 2.0 on my windows vista x64 system but still am having issues with getting the webserver to be seen outside my local network. It is working fine within my local network. Been through several setup tutorials so far, no dice still. For testing purposes I have... (1 Reply)
Discussion started by: davidmanvell
1 Replies

8. Shell Programming and Scripting

How to Merge / combine / join / paste 2 text files side-by-side

I have 2 text files, both have one simple, single column. The 2 files might be the same length, or might not, and if not, it's unknown which one would be longer. For this example, file1 is longer: ---file1 Joe Bob Mary Sally Fred Elmer David ---file2 Tomato House Car... (3 Replies)
Discussion started by: cajunfries
3 Replies

9. Shell Programming and Scripting

Script to place selected columns from a group of files side by side in a new file

Hi Everyone, I need a shell/perl script to bring selected columns from all the files located in a directory and place them in a new file side by side. File1: a b c d 2 3 4 5 f g h i .......... File2: I II III IV w x y z .............. and so on many files are there...... (8 Replies)
Discussion started by: ks_reddy
8 Replies

10. Shell Programming and Scripting

How to print two sql query outputs side by side in excel

Hi, I have to sql queries like select sno,sname from temptable; select deptno,dname from depttable; In excel i want to specify the column number to which my output should be displayed. please help me in this... thanks in advance... (6 Replies)
Discussion started by: prasee
6 Replies
Login or Register to Ask a Question