Visit Our UNIX and Linux User Community


How to Decode an image using openGL


 
Thread Tools Search this Thread
Top Forums Programming How to Decode an image using openGL
# 8  
Old 11-12-2009
Could you post what you have so far please?
# 9  
Old 11-16-2009
Error How to insert JPEGs on each side of the cylinder using openGL

Hi Sir,

Sorry for late Reply ,,, i am in out of station ..

i have code to generate cylinder, but i need to insert images on the surface .


code :

#include <stdlib.h>
#include <string.h>
#include "GL/glut.h"


#define TIMER 100

GLUquadric *myQuad;


static float xrot;
#define TMMODE_SINGLE 2
#define TMMODE_TWOPASS 3
#ifdef GL_HP_texture_lighting
#define TMMODE_HPEXT 4
#endif /* GL_HP_texture_lighting */
static int tmMode;
#define USE_ALPHA_TEST 10
static int alphaTest = 0;

static GLuint textures[2];


static void display( void )
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity ();
gluLookAt (0., 0., 5.,
0., 1., 1.,
0., 1., 0.);

glRotatef (xrot, 0.0, 1.0, 0.0);
glTranslatef (0., 0., 1.);

/* Only pass or first of two passes */
gluCylinder (myQuad, 1.0, 1.0, 4., 24, 8);

if (tmMode == TMMODE_TWOPASS) {
GLfloat white[4] = {1., 1., 1., 1.};

/* second pass here*/
glPushAttrib (GL_ALL_ATTRIB_BITS);
glColor3f (0., 0., 0.);
glDepthFunc (GL_LEQUAL);
glEnable (GL_BLEND);
glLightfv (GL_LIGHT1, GL_SPECULAR, white);
glBindTexture (GL_TEXTURE_2D, textures[1]);

gluCylinder (myQuad, .5, .5, 2., 24, 8);

glPopAttrib ();

/* Bug! Should have popped... */
glBindTexture (GL_TEXTURE_2D, textures[0]);
}

glFlush();
glutSwapBuffers();
}

void reshape(int w, int h)
{
glViewport (0, 0, w, h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (50., (float)w/(float)h, 1., 20.);

/* Leave us in modelview mode for our display routine */
glMatrixMode(GL_MODELVIEW);
}

static void cbMainMenu (int value)
{
GLfloat white[4] = {1., 1., 1., 1.};
GLfloat black[4] = {0., 0., 0., 0.};


if (value == 99) {
exit (0);
}

if (value < USE_ALPHA_TEST)
tmMode = value;

switch (value) {
/* case TMMODE_NONE: {
glDisable (GL_TEXTURE_2D);
glLightfv (GL_LIGHT1, GL_SPECULAR, white);
break;
}*/
case TMMODE_SINGLE: {
glEnable (GL_TEXTURE_2D);
glLightfv (GL_LIGHT1, GL_SPECULAR, white);
#ifdef GL_HP_texture_lighting
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_LIGHTING_MODE_HP, GL_TEXTURE_POST_SPECULAR_HP);
#endif /* GL_HP_texture_lighting */
break;
}
case TMMODE_TWOPASS: {
glEnable (GL_TEXTURE_2D);
glLightfv (GL_LIGHT1, GL_SPECULAR, black);
#ifdef GL_HP_texture_lighting
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_LIGHTING_MODE_HP, GL_TEXTURE_POST_SPECULAR_HP);
#endif /* GL_HP_texture_lighting */
break;
}
#ifdef GL_HP_texture_lighting
case TMMODE_HPEXT: {
glEnable (GL_TEXTURE_2D);
glLightfv (GL_LIGHT1, GL_SPECULAR, white);
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_LIGHTING_MODE_HP, GL_TEXTURE_PRE_SPECULAR_HP);
break;
}
#endif /* GL_HP_texture_lighting */
case USE_ALPHA_TEST: {
alphaTest = ~alphaTest;
if (alphaTest)
glEnable (GL_ALPHA_TEST);
else
glDisable (GL_ALPHA_TEST);
break;
}
}
}


static void timer (int value)
{
xrot += 1.f;
if (xrot > 360.f) xrot -= 360.f;

glutPostRedisplay ();
glutTimerFunc (TIMER, timer, 0);
}

static void initTextureMap (int w, int h, unsigned char *tm)
{
int i, j, ci=w>>2, cj=h>>2;

for (i=0; i<w; i++) {
for (j=0; j<h; j++) {
tm[0] = tm[1] = tm[2] = tm[3] = 0;
if ((i&ci)^(j&cj)) {
/* red has full alpha, black has zero alpha */
tm[0] = tm[3] = 255;
}
tm += 4;
}
}
}

static void init ()
{
int mainMenu;
GLfloat pos[4] = {3., 5., 2., 1.};
GLfloat white[4] = {1., 1., 1., 1.};

xrot = 0.;

glClearColor (.3, .3, .3, 0.);
glColor4f (.0, .0, 1.0, 1.); /* cylinder is grey by default */
glDisable (GL_DITHER);
glEnable (GL_DEPTH_TEST);

/* Set up alpha test to toss 0 alpha */
glAlphaFunc (GL_NOTEQUAL, 0);

/* blending function used in TMMODE_TWOPASS */
glBlendFunc (GL_ONE, GL_ONE);

/* Set up light1 */
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT1);
glLightfv (GL_LIGHT1, GL_POSITION, pos);
glLightfv (GL_LIGHT1, GL_DIFFUSE, white);
glLightfv (GL_LIGHT1, GL_SPECULAR, white);

/* ambient and diffuse will track glColor */
glEnable (GL_COLOR_MATERIAL);
glColorMaterial (GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glMaterialf (GL_FRONT, GL_SHININESS, 30.f);
glMaterialfv (GL_FRONT, GL_SPECULAR, white);

/* Set up texture coord generation */
{
/* Use Z plane for T generation because the cylinder lies along the Z axis */

//

float tPlane[4] = {1., 1., 1., 1.};
glTexGenfv (GL_T, GL_OBJECT_PLANE, tPlane);
}
glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glEnable (GL_TEXTURE_GEN_S);
glEnable (GL_TEXTURE_GEN_T);

/* prepare to use two texture objects */
glGenTextures (2, textures);

/* init first texture object, a red & black checkerboard, ho-hum */
glBindTexture (GL_TEXTURE_2D, textures[0]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
{
#define TDIM 32
unsigned char *pixels;
pixels = (unsigned char *) malloc (TDIM*TDIM*4);
initTextureMap (TDIM, TDIM, pixels);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, TDIM, TDIM,
0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
free (pixels);
}

/* Second texture is a 2x2 white texture map for the sdpecular pass of TMMODE_TWOPASS */
glBindTexture (GL_TEXTURE_2D, textures[1]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
{
unsigned char pixels[2*2*4];
memset (pixels, 0xff, 2*2*4);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 2, 2,
0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
}

/* Leave first texture bound */
glBindTexture (GL_TEXTURE_2D, textures[0]);

myQuad = gluNewQuadric ();

glutDisplayFunc (display);
glutReshapeFunc (reshape);
glutTimerFunc (TIMER, timer, 0);

mainMenu = glutCreateMenu (cbMainMenu);

//glutAddMenuEntry ("No texture mapping", TMMODE_NONE);
glutAddMenuEntry ("Single pass", TMMODE_SINGLE);
glutAddMenuEntry ("Two pass", TMMODE_TWOPASS);
#ifdef GL_HP_texture_lighting
glutAddMenuEntry ("HP pre-specular", TMMODE_HPEXT);
#endif /* GL_HP_texture_lighting */
glutAddMenuEntry ("Toggle alpha test", USE_ALPHA_TEST);
glutAddMenuEntry ("Quit", 99);
glutAttachMenu (GLUT_RIGHT_BUTTON);
// tmMode = TMMODE_NONE;
}

void main(int argc, char** argv)
{
/* Pretty much standard GLUT init code sequence... */
glutInit (&argc,argv);
glutInitDisplayMode (GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize (300,300);
glutInitWindowPosition (0,0);
glutCreateWindow ("specular lighting and texture mapping");

init ();

glutMainLoop ();
}



This is the code i have .. please guide me how to insert images on the surface of the cylinder.. any answer is appreciated..

Previous Thread | Next Thread
Test Your Knowledge in Computers #35
Difficulty: Easy
The IP address 127.0.0.1 is also called 'localhost'.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX Desktop Questions & Answers

Difference between opengl es and directfb

i dont know in which forum to ask this question ..... :( . pardon me if it is not this forum i wanted to know difference between openGL ES and directfb as far i know directfb is alternative to x11 in linux for embedded devices. something like ... application | ... (1 Reply)
Discussion started by: alexzander18
1 Replies

2. Solaris

Solaris 8 and openGL

Hi everybody, Sorry to bother you one more time, but I have a problem with my Solaris 8 installation. Actually, Solaris works well, I can start X and access my desktop (CDE), but I'm having troubles using Cadds (a CAO software). Cadds works, but the 3D visualization is very slow compare to... (4 Replies)
Discussion started by: firstpost
4 Replies

3. Shell Programming and Scripting

matching image files to create one image

Hi, I have two sets of image files. Both sets have names A to Z but set 1 ends with .cdt.png and set 2 ends with .matrix.png. I want set 1 to match with set 2 if the names match (i.e. A.cdt.png will match with A.matrix.png) and with the convert image tool (program for images), it will merge the... (6 Replies)
Discussion started by: kylle345
6 Replies

4. Programming

How to install openGL packages?

Hi, Any one help me regarding how to install openGL packages to work in linux. And i installed some of the packages(gl,glu), but i don't know whether they are installed are not .. Which command is should use to check whether openGL is installed are not .. I am Thankful for any kind of... (3 Replies)
Discussion started by: Ravikishore
3 Replies

5. Programming

Draw a 3D cylinder using openGL.

Hi, please give me, how to code to draw 3D cylinder in openGL, that should be rotated in x-direction. waiting for your reply .. (2 Replies)
Discussion started by: Ravikishore
2 Replies

6. Ubuntu

How to draw cylinder using openGL

Hi Sir, i am new to openGL, i want to know how to draw cylinder using openGL code in C or C++.. And i have to insert bitmap images on cylinder.. How to do this .. please guide me ... Thanking You in advance .. (0 Replies)
Discussion started by: Ravikishore
0 Replies

7. 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

8. AIX

Need to install opengl for GXT4500.

Hi, I try to install opengl bat it give a error that i need the opengl base level fileset 5.3.0.0 I use AIX 5.3 and my oslevel is now 5300-03. Where can i find the opengl files i need (5.3.0.0)? Thanks Peter. (1 Reply)
Discussion started by: xeonbb
1 Replies

9. UNIX for Advanced & Expert Users

Create an Ignite image on tape from Online IgniteUX image

Hi, (HP-UX 11.11) I need to create a tape image of an igniteUX image created on our igniteUX server. That is to say. I have a "Online" image of the igniteUX of the targeted system but I now need to copy it to a useable TAPE (igniteUX) image so i can build an other server from it that is not... (3 Replies)
Discussion started by: Andrek
3 Replies

10. Linux

Help with OpenGL in Fedora Core 4.

I'm pretty much new to this Linux stuff, I installed FC4 the other night to try it out. I'm having a slight problem when launching Quake 3, it's giving me the error GLimp_Init() - could not load OpenGL subsystem I've updated my video drivers to the latest version and went through fglrxconfig,... (3 Replies)
Discussion started by: Filth Pig
3 Replies

Featured Tech Videos