Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Sony Alpha 7 V, anteprima e novità della nuova 30fps, che tende la mano anche ai creator
Sony Alpha 7 V, anteprima e novità della nuova 30fps, che tende la mano anche ai creator
Dopo oltre 4 anni si rinnova la serie Sony Alpha 7 con la quinta generazione, che porta in dote veramente tante novità a partire dai 30fps e dal nuovo sensore partially stacked da 33Mpixel. L'abbiamo provata per un breve periodo, ecco come è andata dopo averla messa alle strette.
realme GT 8 Pro Dream Edition: prestazioni da flagship e anima racing da F1
realme GT 8 Pro Dream Edition: prestazioni da flagship e anima racing da F1
realme e Aston Martin Aramco F1 Team si sono (ri)unite dando alla vita un flagship con chip Snapdragon 8 Elite Gen 5 e design esclusivo ispirato alle monoposto di Formula 1. La Dream Edition introduce la nuova colorazione Lime Essence abbinata al tradizionale Aston Martin Racing Green, decorazioni intercambiabili personalizzate e una confezione a tema F1, intorno a uno smartphone dall'ottima dotazione tecnica con batteria da 7000mAh ricaricabile a 120W e isola fotografica intercambiabile
OVHcloud Summit 2025: le novità del cloud europeo tra sovranità, IA e quantum
OVHcloud Summit 2025: le novità del cloud europeo tra sovranità, IA e quantum
Abbiamo partecipato all'OVHcloud Summit 2025, conferenza annuale in cui l'azienda francese presenta le sue ultime novità. Abbiamo parlato di cloud pubblico e privato, d'intelligenza artificiale, di computer quantistici e di sovranità. Che forse, però, dovremmo chiamare solo "sicurezza"
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 30-03-2005, 12:49   #1
Luc@s
Senior Member
 
L'Avatar di Luc@s
 
Iscritto dal: Apr 2002
Città: Vigevano(PV)
Messaggi: 2124
Problema Openglut

Codice:
#include <GL/openglut.h>
#include <gl/gl.h>
#include <gl/glaux.h>
#include <stdio.h>
#include <stdlib.h>

#define W 800
#define H 600
#define TITLE "Ogl Base"
#define ESC 27
//#define DEBUG

float red=1.0, blue=1.0, green=1.0, x_angle = 0.0, y_angle = 0.0, z_angle = 0.0;
const char * msg = "\tPress UP/DOWN in order to rotate x axis \
                    \tPress LEFT/RIGTH in order to rotate y axis \ 
                    \tPress PAGE UP/PAGE DOWN in order to rotate z axis \
                    \tPress O/P in order to enable/disable ligthning"; 

GLuint		texture[3], filter;	
// ligth
GLfloat LightAmbient[]=  { 0.5f, 0.5f, 0.5f, 1.0f }; 	
GLfloat LightDiffuse[]=  { 1.0f, 1.0f, 1.0f, 1.0f };	
GLfloat LightPosition[]= { 1.0f, 0.0f, 2.0f, 1.0f };


AUX_RGBImageRec *LoadBMP(char *Filename)					// Loads A Bitmap Image
{
	FILE *File=NULL;			
	if (!Filename)								// Make Sure A Filename Was Given
	{
    #ifdef DEBUG  
    FILE * fout = fopen("error.txt", "a");
    fprintf(fout,"Texture Not Exist!");
    fclose(fout);
    #endif 
		return NULL;							// If Not Return NULL
	}
	File=fopen(Filename,"r");
	if (File)								// Does The File Exist?
	{
    #ifdef DEBUG 
    FILE * fout = fopen("info.txt", "a");
    fprintf(fout,"Texture Loaded!");
    fclose(fout);
    #endif
		fclose(File);							// Close The Handle
		return auxDIBImageLoad(Filename);				// Load The Bitmap And Return A Pointer
	}
}

int LoadGLTextures(char *Filename)								// Load Bitmaps And Convert To Textures
{
 int Status=FALSE;
 AUX_RGBImageRec *TextureImage[1];
 // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
 if (TextureImage[0]=LoadBMP(Filename))
 {
		Status=TRUE;
    glGenTextures(3, &texture[0]);	
    // Create Nearest Filtered Texture
		glBindTexture(GL_TEXTURE_2D, texture[0]);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // ( NEW )
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // ( NEW )
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
  
		// Create Linear Filtered Texture
		glBindTexture(GL_TEXTURE_2D, texture[1]);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

		// Create MipMapped Texture
		glBindTexture(GL_TEXTURE_2D, texture[2]);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); // ( NEW )
    
    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); // ( NEW )

 }
 if (TextureImage[0])							// If Texture Exists
 {
		if (TextureImage[0]->data)					// If Texture Image Exists
		{
			free(TextureImage[0]->data);				// Free The Texture Image Memory
		}

		free(TextureImage[0]);						// Free The Image Structure
	}
	return Status;
}

void renderScene() 
{
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	
	if (!LoadGLTextures("Data/Conan2.bmp"))							// Jump To Texture Loading Routine ( NEW )
	{
		return;							// If Texture Didn't Load Return FALSE ( NEW )
	}
	
  glPushMatrix(); // save previus object
  
  glRotatef(x_angle,1.0,0.0,0.0); // Rotate On The X Axis By x_angle
  glRotatef(y_angle,0.0,1.0,0.0); // Rotate On The Y Axis By y_angle
  glRotatef(z_angle,0.0,0.0,1.0); // Rotate On The Z Axis By z_angle
  
	glColor3f(red,green,blue);
	
	glBindTexture(GL_TEXTURE_2D, texture[filter]);				// Select Our Texture

	glBegin(GL_QUADS);								
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
		// Back Face
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
		// Top Face
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		// Bottom Face
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		// Right face
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		// Left Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		
	glEnd();
	
  glPopMatrix();
	
	glutSwapBuffers();


}

void changeSize(int w, int h) 
{
 if(h == 0)
		h = 1;

	float ratio = 1.0* w / h;
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	// Set the viewport to be the entire window
	glViewport(0, 0, w, h);

	// Set the correct perspective.
	gluPerspective(45,ratio,1,1000);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(0.0,0.0,5.0, 
		      0.0,0.0,-1.0,
			  0.0f,1.0f,0.0f);
}


void processNormalKeys(unsigned char key, int x, int y) 
{

     if(key == 'q' || key == ESC)
     {
            #ifdef DEBUG 
            FILE * fout = fopen("info.txt", "a");
            fprintf(fout,"Application Exit with 0 result\n");
            fclose(fout);
            #endif 
            exit(0);   
     }
     if(key == 'o')
            glEnable(GL_LIGHTING);
     if(key == 'p')
            glDisable(GL_LIGHTING);	   
     
}
/*
GLUT_KEY_F1		        F1 function key
GLUT_KEY_F2		        F2 function key
GLUT_KEY_F3		        F3 function key
GLUT_KEY_F4		        F4 function key
GLUT_KEY_F5		        F5 function key
GLUT_KEY_F6		        F6 function key
GLUT_KEY_F7		        F7 function key
GLUT_KEY_F8		        F8 function key
GLUT_KEY_F9		        F9 function key
GLUT_KEY_F10		      F10 function key
GLUT_KEY_F11		      F11 function key
GLUT_KEY_F12		      F12 function key
GLUT_KEY_LEFT		      Left function key
GLUT_KEY_RIGHT	      Up function key
GLUT_KEY_UP		        Right function key
GLUT_KEY_DOWN		      Down function key
GLUT_KEY_PAGE_UP      Page Up function key
GLUT_KEY_PAGE_DOWN	  Page Down function key
GLUT_KEY_HOME		      Home function key
GLUT_KEY_END		      End function key
GLUT_KEY_INSERT		    Insert function key
*/
void processSpecialKeys(int key, int x, int y) 
{
 switch(key) 
 {
		case GLUT_KEY_F1 : 
				red = 1.0; 
				green = 0.0; 
				blue = 0.0; break;
		case GLUT_KEY_F2 : 
				red = 0.0; 
				green = 1.0; 
				blue = 0.0; break;
		case GLUT_KEY_F3 : 
				red = 0.0; 
				green = 0.0; 
				blue = 1.0; break;
		case GLUT_KEY_F5 : 
        filter = 0; break;
		case GLUT_KEY_F6 : 
        filter = 1; break;
		case GLUT_KEY_F7 : 
        filter = 2; break;
				
		case GLUT_KEY_DOWN : 
        x_angle++;  break;
		case GLUT_KEY_UP : 
        x_angle--;  break;
        
		case GLUT_KEY_PAGE_DOWN : 
        z_angle--;  break;
		case GLUT_KEY_PAGE_UP : 
        z_angle++;  break;
        
		case GLUT_KEY_RIGHT : 
        y_angle++;  break;
		case GLUT_KEY_LEFT : 
        y_angle--;  break;
        
    case GLUT_KEY_F11:
         MessageBox(NULL, msg, "Help.....", MB_ICONINFORMATION);
                    break;
	}

}



int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
	
	glutInitWindowPosition(100,100);
	glutInitWindowSize(W,H);
	
	glutCreateWindow(TITLE);
	
	glutDisplayFunc(renderScene);
	glutReshapeFunc(changeSize);
	glutIdleFunc(renderScene);
	glutKeyboardFunc(processNormalKeys);
	glutSpecialFunc(processSpecialKeys);	

 // enable depth testing
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);						// Enable Texture Mapping ( NEW )
	glShadeModel(GL_SMOOTH);						// Enable Smooth Shading
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);					// Black Background
	glClearDepth(1.0f);
	glDepthFunc(GL_LEQUAL);							// The Type Of Depth Testing To Do
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	// Setup Light
	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
  glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
  glEnable(GL_LIGHT1);
	glutMainLoop();
	return 0;
}
Questo pgm dopo un 25 secondi mi va in 'Out of memory' e mi sballa tutto.....secondo voi a cosa è dovuto??

p.s: la bmp è una semplice bmp 256X256
__________________
Gnu/Linux User
Luc@s è offline   Rispondi citando il messaggio o parte di esso
Old 30-03-2005, 16:05   #2
Luc@s
Senior Member
 
L'Avatar di Luc@s
 
Iscritto dal: Apr 2002
Città: Vigevano(PV)
Messaggi: 2124
up
__________________
Gnu/Linux User
Luc@s è offline   Rispondi citando il messaggio o parte di esso
Old 31-03-2005, 18:27   #3
Luc@s
Senior Member
 
L'Avatar di Luc@s
 
Iscritto dal: Apr 2002
Città: Vigevano(PV)
Messaggi: 2124
__________________
Gnu/Linux User
Luc@s è offline   Rispondi citando il messaggio o parte di esso
Old 31-03-2005, 19:58   #4
DanieleC88
Senior Member
 
L'Avatar di DanieleC88
 
Iscritto dal: Jun 2002
Città: Dublin
Messaggi: 5989
Da una occhiata veloce, direi che il codice è a posto. Puoi mandare l'output di un debugger? Io ho fatto un programmino simile sotto Linux (SDL+OpenGL) e va alla perfezione. Magari un'altra volta ti mando un po' di codice.
__________________

C'ho certi cazzi Mafa' che manco tu che sei pratica li hai visti mai!
DanieleC88 è offline   Rispondi citando il messaggio o parte di esso
Old 31-03-2005, 21:06   #5
Luc@s
Senior Member
 
L'Avatar di Luc@s
 
Iscritto dal: Apr 2002
Città: Vigevano(PV)
Messaggi: 2124
Codice:
#include <GL/openglut.h>
#include <gl/gl.h>
#include <gl/glaux.h>
#include "Conf.h"

#define W 800
#define H 600

#define BLANDING_DEPTH 0.5 // 50%

#define TITLE "Ogl Base"
#define ESC 27
//#define DEBUG

float red=1.0, blue=1.0, green=1.0, alpha = BLANDING_DEPTH, x_angle = 0.0, y_angle = 0.0, z_angle = 0.0;

const char * msg = "\tPress L in order to enable/disable ligthning \
                    \tPress B  in order to enable/disable blending \
                    \tPress F5 in order to use no filtering \
                    \tPress F6 in order to use linear filtering \
                    \tPress F7 in order to use mipmapped filtering(all dimension accepted and higthest quality)";  

GLuint	texture[1], tx_count = 0;	
bool blend = false, ligth = false;

// ligth
GLfloat LightAmbient[]=  { 0.5f, 0.5f, 0.5f, 1.0f }; 	
GLfloat LightDiffuse[]=  { 1.0f, 1.0f, 1.0f, 1.0f };	
GLfloat LightPosition[]= { 1.0f, 0.0f, 2.0f, 1.0f };


AUX_RGBImageRec *LoadBMP(const char *Filename)					// Loads A Bitmap Image
{
	FILE *File=NULL;			
	if (!Filename)								// Make Sure A Filename Was Given
	{
    #ifdef DEBUG  
    FILE * fout = fopen("error.txt", "a");
    fprintf(fout,"Texture Not Exist!\n");
    fclose(fout);
    #endif 
		return NULL;							// If Not Return NULL
	}
	File=fopen(Filename,"r");
	if (File)								// Does The File Exist?
	{
    #ifdef DEBUG 
    tx_count++;
    FILE * fout = fopen("info.txt", "a");
    fprintf(fout,"Texture Loaded n %i!\n", tx_count);
    fclose(fout);
    #endif
		fclose(File);							// Close The Handle
		return auxDIBImageLoad(Filename);				// Load The Bitmap And Return A Pointer
	}
}

int LoadGLTextures(const char *Filename)								// Load Bitmaps And Convert To Textures
{
 int Status=FALSE;
 AUX_RGBImageRec *TextureImage[1];
 // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
 if (TextureImage[0]=LoadBMP(Filename))
 {
		Status=TRUE;
    glGenTextures(1, &texture[0]);

		// Create MipMapped Texture
		glBindTexture(GL_TEXTURE_2D, texture[0]);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); // ( NEW )
    
    gluBuild2DMipmaps(GL_TEXTURE_2D, 1, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); // ( NEW )

 }
 if (TextureImage[0])							// If Texture Exists
 {
		if (TextureImage[0]->data)					// If Texture Image Exists
		{
			free(TextureImage[0]->data);				// Free The Texture Image Memory
		}

		free(TextureImage[0]);						// Free The Image Structure
	}
	return Status;
}

void renderScene() 
{
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  

  glPushMatrix(); // save previus object
  
  glRotatef(x_angle,1.0,0.0,0.0); // Rotate On The X Axis By x_angle
  glRotatef(y_angle,0.0,1.0,0.0); // Rotate On The Y Axis By y_angle
  glRotatef(z_angle,0.0,0.0,1.0); // Rotate On The Z Axis By z_angle
  
	glColor4f(red,green,blue, alpha);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);
	
	glBindTexture(GL_TEXTURE_2D, texture[0]);				// Select Our Texture

	glBegin(GL_QUADS);								
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
		// Back Face
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
		// Top Face
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		// Bottom Face
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		// Right face
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		// Left Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
	glEnd();
	
  glPopMatrix();
	
	glutSwapBuffers();


}

void changeSize(int w, int h) 
{
 if(h == 0)
		h = 1;

	float ratio = 1.0* w / h;
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	// Set the viewport to be the entire window
	glViewport(0, 0, w, h);

	// Set the correct perspective.
	gluPerspective(45,ratio,1,1000);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(0.0,0.0,5.0, 
		      0.0,0.0,-1.0,
			  0.0f,1.0f,0.0f);
}


void processNormalKeys(unsigned char key, int x, int y) 
{

     if(key == 'q' || key == ESC)
     {
            #ifdef DEBUG 
            FILE * fout = fopen("info.txt", "a");
            fprintf(fout,"Application Exit with 0 result\n");
            fclose(fout);
            #endif 
            exit(0);   
     }
     if(key == 'l' || key == 'L')
     {
            ligth = !ligth;
            if(ligth)
            {
             glEnable(GL_LIGHTING);
            }
            else
            {
             glDisable(GL_LIGHTING);
            }        
     }	
     if(key == 'b' || key == 'B')
     {   
		     blend = !blend;				// Toggle blend TRUE / FALSE	
		     if(blend)				// Is blend TRUE?
		     {
			    glEnable(GL_BLEND);		// Turn Blending On
			    glDisable(GL_DEPTH_TEST);	// Turn Depth Testing Off
		     }
		     else					// Otherwise
		     {
			    glDisable(GL_BLEND);		// Turn Blending Off
			    glEnable(GL_DEPTH_TEST);	// Turn Depth Testing On
         }
     }

}
/*
GLUT_KEY_F1		        F1 function key
GLUT_KEY_F2		        F2 function key
GLUT_KEY_F3		        F3 function key
GLUT_KEY_F4		        F4 function key
GLUT_KEY_F5		        F5 function key
GLUT_KEY_F6		        F6 function key
GLUT_KEY_F7		        F7 function key
GLUT_KEY_F8		        F8 function key
GLUT_KEY_F9		        F9 function key
GLUT_KEY_F10		      F10 function key
GLUT_KEY_F11		      F11 function key
GLUT_KEY_F12		      F12 function key
GLUT_KEY_LEFT		      Left function key
GLUT_KEY_RIGHT	      Up function key
GLUT_KEY_UP		        Right function key
GLUT_KEY_DOWN		      Down function key
GLUT_KEY_PAGE_UP      Page Up function key
GLUT_KEY_PAGE_DOWN	  Page Down function key
GLUT_KEY_HOME		      Home function key
GLUT_KEY_END		      End function key
GLUT_KEY_INSERT		    Insert function key
*/
void processSpecialKeys(int key, int x, int y) 
{
 switch(key) 
 {
		case GLUT_KEY_F1 : 
				red   = 1.0; 
				green = 0.0; 
				blue  = 0.0; break;
		case GLUT_KEY_F2 : 
				red   = 0.0; 
				green = 1.0; 
				blue  = 0.0; break;
		case GLUT_KEY_F3 : 
				red   = 0.0; 
				green = 0.0; 
				blue  = 1.0; break;
		case GLUT_KEY_F4 : 
				red   = 1.0; 
				green = 1.0; 
				blue  = 1.0; break;
          			
		case GLUT_KEY_DOWN : 
        x_angle++;  break;
		case GLUT_KEY_UP : 
        x_angle--;  break;
        
		case GLUT_KEY_PAGE_DOWN : 
        z_angle--;  break;
		case GLUT_KEY_PAGE_UP : 
        z_angle++;  break;
        
		case GLUT_KEY_RIGHT : 
        y_angle++;  break;
		case GLUT_KEY_LEFT : 
        y_angle--;  break;
        
    case GLUT_KEY_F11:
         MessageBox(NULL, msg, "Help.....", MB_ICONINFORMATION);
                    break;
	}

}



int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
	
	glutInitWindowPosition(100,100);
	glutInitWindowSize(W,H);
	
	glutCreateWindow(TITLE);
	
	glutDisplayFunc(renderScene);
	glutReshapeFunc(changeSize);
	glutIdleFunc(renderScene);
	glutKeyboardFunc(processNormalKeys);
	glutSpecialFunc(processSpecialKeys);	

	//glEnable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);						// Enable Texture Mapping ( NEW )
	glShadeModel(GL_SMOOTH);						// Enable Smooth Shading
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);					// Black Background
	glClearDepth(1.0f);
	glDepthFunc(GL_LEQUAL);							// The Type Of Depth Testing To Do
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	// Setup Light
	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
  glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
  glEnable(GL_LIGHT1);
  
 	if (!LoadGLTextures(TEXTURE))							// Jump To Texture Loading Routine ( NEW )
	{
    free(texture); 
		return -1;							// If Texture Didn't Load Return FALSE ( NEW )
	}
	
	glutMainLoop();
	return 0;
}
//:~
__________________
Gnu/Linux User
Luc@s è offline   Rispondi citando il messaggio o parte di esso
Old 31-03-2005, 21:14   #6
AnonimoVeneziano
Senior Member
 
L'Avatar di AnonimoVeneziano
 
Iscritto dal: Aug 2001
Città: San Francisco, CA, USA
Messaggi: 13827
Non ho capito se adesso hai risolto o no ...


Comunque se riesci ad evitare l'utilizzo di GLaux è meglio , oltre ad essere codice non portabile è anche vecchio .

Potresti usare questo per caricare le BMP :

http://chaoslizard.sourceforge.net/glbmp/

Ciao
__________________
GPU Compiler Engineer
AnonimoVeneziano è offline   Rispondi citando il messaggio o parte di esso
Old 31-03-2005, 21:38   #7
Luc@s
Senior Member
 
L'Avatar di Luc@s
 
Iscritto dal: Apr 2002
Città: Vigevano(PV)
Messaggi: 2124
Codice:
 
#include <GL/openglut.h>
#include <gl/gl.h>
#include "glbmp.h"
#include "Conf.h"

#define W 800
#define H 600

#define BLANDING_DEPTH 0.5 // 50%

#define TITLE "Ogl Base"
#define ESC 27
//#define DEBUG

float red=1.0, blue=1.0, green=1.0, alpha = BLANDING_DEPTH, x_angle = 0.0, y_angle = 0.0, z_angle = 0.0; 

GLuint texture = 0, tx_count = 0;	
bool blend = false, ligth = false;

// ligth
GLfloat LightAmbient[]=  { 0.5f, 0.5f, 0.5f, 1.0f }; 	
GLfloat LightDiffuse[]=  { 1.0f, 1.0f, 1.0f, 1.0f };	
GLfloat LightPosition[]= { 1.0f, 0.0f, 2.0f, 1.0f };

glbmp_t bitmap;

void LoadBMP(const char *Filename)					// Loads A Bitmap Image
{
	FILE *File=NULL;			
	if (!Filename)								// Make Sure A Filename Was Given
	{
    #ifdef DEBUG  
    FILE * fout = fopen("error.txt", "a");
    fprintf(fout,"Texture Not Exist!\n");
    fclose(fout);
    #endif 
		return;							// If Not Return NULL
	}
	File=fopen(Filename,"r");
	if (File)								// Does The File Exist?
	{
    #ifdef DEBUG 
    tx_count++;
    FILE * fout = fopen("info.txt", "a");
    fprintf(fout,"Texture Loaded n %i!\n", tx_count);
    fclose(fout);
    #endif
		fclose(File);							// Close The Handle
		glbmp_LoadBitmap(Filename, 0, &bitmap);				// Load The Bitmap
	}
}

int LoadGLTextures(const char *Filename)								// Load Bitmaps And Convert To Textures
{
 int Status=FALSE;
 // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
 if (glbmp_LoadBitmap(Filename, 0, &bitmap))
 {
		Status=TRUE;
   //generate and bind the OpenGL texture
   glGenTextures(1, &texture);
   glBindTexture(GL_TEXTURE_2D, texture);

   //copy data from bitmap into texture
   glTexImage2D(GL_TEXTURE_2D, 0, 3, bitmap.width, bitmap.height,
                0, GL_RGB, GL_UNSIGNED_BYTE, bitmap.rgb_data);

   //set up texture filtering
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

   //free the bitmap
   glbmp_FreeBitmap(&bitmap);
 }
	return Status;
}

void renderScene() 
{
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  
  glPushMatrix(); // save previus object
  
  glRotatef(x_angle,1.0,0.0,0.0); // Rotate On The X Axis By x_angle
  glRotatef(y_angle,0.0,1.0,0.0); // Rotate On The Y Axis By y_angle
  glRotatef(z_angle,0.0,0.0,1.0); // Rotate On The Z Axis By z_angle
  
	glColor4f(red,green,blue, alpha);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);
	
	glBindTexture(GL_TEXTURE_2D, texture);				// Select Our Texture

	glBegin(GL_QUADS);								
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
		// Back Face
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
		// Top Face
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		// Bottom Face
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		// Right face
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		// Left Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
	glEnd();
	
  glPopMatrix();
	
	glutSwapBuffers();


}

void changeSize(int w, int h) 
{
 if(h == 0)
		h = 1;

	float ratio = 1.0* w / h;
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	// Set the viewport to be the entire window
	glViewport(0, 0, w, h);

	// Set the correct perspective.
	gluPerspective(45,ratio,1,1000);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(0.0,0.0,5.0, 
		      0.0,0.0,-1.0,
			  0.0f,1.0f,0.0f);
}


void processNormalKeys(unsigned char key, int x, int y) 
{

     if(key == 'q' || key == ESC)
     {
            #ifdef DEBUG 
            FILE * fout = fopen("info.txt", "a");
            fprintf(fout,"Application Exit with 0 result\n");
            fclose(fout);
            #endif 
            exit(0);   
     }
     if(key == 'l' || key == 'L')
     {
            ligth = !ligth;
            if(ligth)
            {
             glEnable(GL_LIGHTING);
            }
            else
            {
             glDisable(GL_LIGHTING);
            }        
     }	
     if(key == 'b' || key == 'B')
     {   
		     blend = !blend;				// Toggle blend TRUE / FALSE	
		     if(blend)				// Is blend TRUE?
		     {
			    glEnable(GL_BLEND);		// Turn Blending On
			    glDisable(GL_DEPTH_TEST);	// Turn Depth Testing Off
		     }
		     else					// Otherwise
		     {
			    glDisable(GL_BLEND);		// Turn Blending Off
			    glEnable(GL_DEPTH_TEST);	// Turn Depth Testing On
         }
     }

}
/*
GLUT_KEY_F1		        F1 function key
GLUT_KEY_F2		        F2 function key
GLUT_KEY_F3		        F3 function key
GLUT_KEY_F4		        F4 function key
GLUT_KEY_F5		        F5 function key
GLUT_KEY_F6		        F6 function key
GLUT_KEY_F7		        F7 function key
GLUT_KEY_F8		        F8 function key
GLUT_KEY_F9		        F9 function key
GLUT_KEY_F10		      F10 function key
GLUT_KEY_F11		      F11 function key
GLUT_KEY_F12		      F12 function key
GLUT_KEY_LEFT		      Left function key
GLUT_KEY_RIGHT	      Up function key
GLUT_KEY_UP		        Right function key
GLUT_KEY_DOWN		      Down function key
GLUT_KEY_PAGE_UP      Page Up function key
GLUT_KEY_PAGE_DOWN	  Page Down function key
GLUT_KEY_HOME		      Home function key
GLUT_KEY_END		      End function key
GLUT_KEY_INSERT		    Insert function key
*/
void processSpecialKeys(int key, int x, int y) 
{
 switch(key) 
 {
		case GLUT_KEY_F1 : 
				red   = 1.0; 
				green = 0.0; 
				blue  = 0.0; break;
		case GLUT_KEY_F2 : 
				red   = 0.0; 
				green = 1.0; 
				blue  = 0.0; break;
		case GLUT_KEY_F3 : 
				red   = 0.0; 
				green = 0.0; 
				blue  = 1.0; break;
		case GLUT_KEY_F4 : 
				red   = 1.0; 
				green = 1.0; 
				blue  = 1.0; break;
          			
		case GLUT_KEY_DOWN : 
        x_angle--;  break;
		case GLUT_KEY_UP : 
        x_angle++;  break;

		case GLUT_KEY_PAGE_UP : 
        z_angle++;  break;        
		case GLUT_KEY_PAGE_DOWN : 
        z_angle--;  break;
        
		case GLUT_KEY_RIGHT : 
        y_angle++;  break;
		case GLUT_KEY_LEFT : 
        y_angle--;  break;
        
    case GLUT_KEY_F11:
         MessageBox(NULL, "Press L in order to enable/disable ligthning \nPress B  in order to enable/disable blending", "Help.....", MB_ICONINFORMATION);
                    break;
	}

}



int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
	
	glutInitWindowPosition(100,100);
	glutInitWindowSize(W,H);
	
	glutCreateWindow(TITLE);
	
	glutDisplayFunc(renderScene);
	glutReshapeFunc(changeSize);
	glutIdleFunc(renderScene);
	glutKeyboardFunc(processNormalKeys);
	glutSpecialFunc(processSpecialKeys);	

	//glEnable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);						// Enable Texture Mapping ( NEW )
	glShadeModel(GL_SMOOTH);						// Enable Smooth Shading
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);					// Black Background
	glClearDepth(1.0f);
	glDepthFunc(GL_LEQUAL);							// The Type Of Depth Testing To Do
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	// Setup Light
	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
  glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
  glEnable(GL_LIGHT1);
  
 	if (!LoadGLTextures(TEXTURE))							// Jump To Texture Loading Routine ( NEW )
	{ 
		return -1;							// If Texture Didn't Load Return FALSE ( NEW )
	}
	
	glutMainLoop();
	return 0;
}
//:~
Con la tua lib....mi si apre e si chiude subito senza mostrare nulla :'(
__________________
Gnu/Linux User
Luc@s è offline   Rispondi citando il messaggio o parte di esso
Old 01-04-2005, 00:09   #8
AnonimoVeneziano
Senior Member
 
L'Avatar di AnonimoVeneziano
 
Iscritto dal: Aug 2001
Città: San Francisco, CA, USA
Messaggi: 13827
Lucas , il tuo codice ha qualche problema .

prima di tutto le textures non si dichiarano come variabili ma come arrays.

Quindi :

GLuint texture[1];

e non

GLuint texture;



L'errore a riguardo della dichiarazione della texture porta a dover modificare altre linee, tra le quali :
Codice:
glGenTextures(1, &texture);
   glBindTexture(GL_TEXTURE_2D, texture);

   //copy data from bitmap into texture
   glTexImage2D(GL_TEXTURE_2D, 0, 3, bitmap.width, bitmap.height,
                0, GL_RGB, GL_UNSIGNED_BYTE, bitmap.rgb_data);

   //set up texture filtering
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
che devono diventare :

Codice:
glGenTextures(1, texture);
   glBindTexture(GL_TEXTURE_2D, texture[0]);

   //set up texture filtering
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

//copy data from bitmap into texture
   glTexImage2D(GL_TEXTURE_2D, 0, 3, bitmap.width, bitmap.height,
                0, GL_RGB, GL_UNSIGNED_BYTE, bitmap.rgb_data);
(io preferisco mettere glTexImage2D dopo glTexParameteri, quindi te l'ho messo sotto)

Inoltre non abiliti il DEPTH test all' inizializzazione creando un casino quando il blending è disabilitato. E non solo, non abiliti la finestra al DEPTH testing usando GLUT_DEPTH con glutInitDisplayMode() lasciando quindi il DEPTH test sempre disabilitato!! Già che ci sei abilita pure l'alpha channel con GLUT_ALPHA .

Un altra cosa che non fai è specificare i vettori Normali con glNormal3f() per ogni faccia del cubo creando così casini con il lighting quando questo viene abilitato .

Un altra cosa , luce in inglese si scrive "light", non "ligth" (questo però non l'ho corretto)

Quindi il codice finale io lo trasformerei così (il programma è stato modificato un po' per permettemi di compilarlo sotto linux con GCC, tra le modifiche la sostituzione delle variabili "bool" con "int") Il programma si lancia con "nomeprogramma filetexture.bmp" ovviamente la texture deve essere di dimensioni standard per opengl , ossia con altezza e larghezza o 64 o 128 o 256:

Codice:
#include <GL/openglut.h>
#include <GL/gl.h>
#include <stdio.h>
#include <stdlib.h>
#include "glbmp.h"

#define W 800
#define H 600

#define BLANDING_DEPTH 0.5 // 50%

#define TITLE "Ogl Base"
#define ESC 27
//#define DEBUG

float red=1.0, blue=1.0, green=1.0, alpha = BLANDING_DEPTH, x_angle = 0.0, y_angle = 0.0, z_angle = 0.0; 

GLuint texture[1] = { 0}, tx_count = 0;	
int blend = 0, ligth = 0;

// ligth
GLfloat LightAmbient[]=  { 0.5f, 0.5f, 0.5f, 1.0f }; 	
GLfloat LightDiffuse[]=  { 1.0f, 1.0f, 1.0f, 1.0f };	
GLfloat LightPosition[]= { 1.0f, 0.0f, 2.0f, 1.0f };

glbmp_t bitmap;

void LoadBMP(const char *Filename)					// Loads A Bitmap Image
{
	FILE *File=NULL;			
	if (!Filename)								// Make Sure A Filename Was Given
	{
    #ifdef DEBUG  
    FILE * fout = fopen("error.txt", "a");
    fprintf(fout,"Texture Not Exist!\n");
    fclose(fout);
    #endif 
		return;							// If Not Return NULL
	}
	File=fopen(Filename,"r");
	if (File)								// Does The File Exist?
	{
    #ifdef DEBUG 
    tx_count++;
    FILE * fout = fopen("info.txt", "a");
    fprintf(fout,"Texture Loaded n %i!\n", tx_count);
    fclose(fout);
    #endif
		fclose(File);							// Close The Handle
		glbmp_LoadBitmap(Filename, 0, &bitmap);				// Load The Bitmap
	}
}

int LoadGLTextures(const char *Filename)								// Load Bitmaps And Convert To Textures
{
 int Status=0;
 // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
 if (glbmp_LoadBitmap(Filename, 0, &bitmap))
 {
		Status=1;
   //generate and bind the OpenGL texture
   glGenTextures(1, texture);
   glBindTexture(GL_TEXTURE_2D, texture[0]);

   //copy data from bitmap into texture
  glTexImage2D(GL_TEXTURE_2D, 0, 3, bitmap.width, bitmap.height,
                0, GL_RGB, GL_UNSIGNED_BYTE, bitmap.rgb_data);
   //set up texture filtering
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

   //free the bitmap
   glbmp_FreeBitmap(&bitmap);
 }
	return Status;
}

void renderScene() 
{
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  
  glPushMatrix(); // save previus object

  glRotatef(x_angle,1.0,0.0,0.0); // Rotate On The X Axis By x_angle
  glRotatef(y_angle,0.0,1.0,0.0); // Rotate On The Y Axis By y_angle
  glRotatef(z_angle,0.0,0.0,1.0); // Rotate On The Z Axis By z_angle
  
	glColor4f(red,green,blue, alpha);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);
	
	glBindTexture(GL_TEXTURE_2D, texture[0]);				// Select Our Texture

	glBegin(GL_QUADS);							        glNormal3f(0.0f, 0.0f, 1.0f);	
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
		// Back Face
		glNormal3f(0.0f, 0.0f, -1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
		// Top Face
		
		glNormal3f(0.0f,1.0f, 0.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		// Bottom Face
		glNormal3f(0.0f, -1.0f, 0.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		// Right face
		glNormal3f(1.0f, 0.0f, 0.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		// Left Face
		glNormal3f(-1.0f, 0.0f, 0.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
	glEnd();
	glPopMatrix();
	
	glutSwapBuffers();


}

void changeSize(int w, int h) 
{
 if(h == 0)
		h = 1;

	float ratio = 1.0* w / h;
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	
	// Set the viewport to be the entire window
	glViewport(0, 0, w, h);

	// Set the correct perspective.
	gluPerspective(45,ratio,1,1000);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(0.0,0.0,5.0, 
		      0.0,0.0,-1.0,
			  0.0f,1.0f,0.0f);
}


void processNormalKeys(unsigned char key, int x, int y) 
{

     if(key == 'q' || key == ESC)
     {
            #ifdef DEBUG 
            FILE * fout = fopen("info.txt", "a");
            fprintf(fout,"Application Exit with 0 result\n");
            fclose(fout);
            #endif 
            exit(0);   
     }
     if(key == 'l' || key == 'L')
     {
            ligth = !ligth;
            if(ligth)
            {
             glEnable(GL_LIGHTING);
            }
            else
            {
             glDisable(GL_LIGHTING);
            }        
     }	
     if(key == 'b' || key == 'B')
     {   
		     blend = !blend;				// Toggle blend TRUE / FALSE	
		     if(blend)				// Is blend TRUE?
		     {
			    glEnable(GL_BLEND);		// Turn Blending On
			    glDisable(GL_DEPTH_TEST);	// Turn Depth Testing Off
		     }
		     else					// Otherwise
		     {
			    glDisable(GL_BLEND);		// Turn Blending Off
			    glEnable(GL_DEPTH_TEST);	// Turn Depth Testing On
         }
     }

}
/*
GLUT_KEY_F1		        F1 function key
GLUT_KEY_F2		        F2 function key
GLUT_KEY_F3		        F3 function key
GLUT_KEY_F4		        F4 function key
GLUT_KEY_F5		        F5 function key
GLUT_KEY_F6		        F6 function key
GLUT_KEY_F7		        F7 function key
GLUT_KEY_F8		        F8 function key
GLUT_KEY_F9		        F9 function key
GLUT_KEY_F10		      F10 function key
GLUT_KEY_F11		      F11 function key
GLUT_KEY_F12		      F12 function key
GLUT_KEY_LEFT		      Left function key
GLUT_KEY_RIGHT	      Up function key
GLUT_KEY_UP		        Right function key
GLUT_KEY_DOWN		      Down function key
GLUT_KEY_PAGE_UP      Page Up function key
GLUT_KEY_PAGE_DOWN	  Page Down function key
GLUT_KEY_HOME		      Home function key
GLUT_KEY_END		      End function key
GLUT_KEY_INSERT		    Insert function key
*/
void processSpecialKeys(int key, int x, int y) 
{
 switch(key) 
 {
		case GLUT_KEY_F1 : 
				red   = 1.0; 
				green = 0.0; 
				blue  = 0.0; break;
		case GLUT_KEY_F2 : 
				red   = 0.0; 
				green = 1.0; 
				blue  = 0.0; break;
		case GLUT_KEY_F3 : 
				red   = 0.0; 
				green = 0.0; 
				blue  = 1.0; break;
		case GLUT_KEY_F4 : 
				red   = 1.0; 
				green = 1.0; 
				blue  = 1.0; break;
          			
		case GLUT_KEY_DOWN : 
        x_angle--;  break;
		case GLUT_KEY_UP : 
        x_angle++;  break;

		case GLUT_KEY_PAGE_UP : 
        z_angle++;  break;        
		case GLUT_KEY_PAGE_DOWN : 
        z_angle--;  break;
        
		case GLUT_KEY_RIGHT : 
        y_angle++;  break;
		case GLUT_KEY_LEFT : 
        y_angle--;  break;
        
	}

}



int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH| GLUT_ALPHA);
	
	glutInitWindowPosition(100,100);
	glutInitWindowSize(W,H);
	
	glutCreateWindow(TITLE);
	
	glutDisplayFunc(renderScene);
	glutReshapeFunc(changeSize);
	glutIdleFunc(renderScene);
	glutKeyboardFunc(processNormalKeys);
	glutSpecialFunc(processSpecialKeys);	

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);						// Enable Texture Mapping ( NEW )
	glShadeModel(GL_SMOOTH);						// Enable Smooth Shading
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);					// Black Background
	glClearDepth(1.0f);
	glDepthFunc(GL_LEQUAL);							// The Type Of Depth Testing To Do
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	// Setup Light
	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
  glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
  glEnable(GL_LIGHT1);
 
   		 if (!LoadGLTextures(argv[1]))							// Jump To Texture Loading Routine ( NEW )
	{ 
		return -1;							// If Texture Didn't Load Return FALSE ( NEW )
	}     
	
	glutMainLoop();
	return 0;
}
//:~
Ciao
__________________
GPU Compiler Engineer

Ultima modifica di AnonimoVeneziano : 01-04-2005 alle 00:12.
AnonimoVeneziano è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Sony Alpha 7 V, anteprima e novità della nuova 30fps, che tende la mano anche ai creator Sony Alpha 7 V, anteprima e novità della ...
realme GT 8 Pro Dream Edition: prestazioni da flagship e anima racing da F1 realme GT 8 Pro Dream Edition: prestazioni da fl...
OVHcloud Summit 2025: le novità del cloud europeo tra sovranità, IA e quantum OVHcloud Summit 2025: le novità del cloud...
Un mostro da MSI: QD-OLED WQHD a 500 Hz con AI Care e DisplayPort 2.1a Un mostro da MSI: QD-OLED WQHD a 500 Hz con AI C...
DJI Neo 2 in prova: il drone da 160 grammi guadagna il gimbal e molto altro DJI Neo 2 in prova: il drone da 160 grammi guada...
Anche a Bergamo controlli sulle e-bike: ...
Mario Kart World, con l'ultimo aggiornam...
Oracle apre una seconda Region per il cl...
Euro NCAP 2026, cambiano completamente i...
In Russia centinaia di Porsche diventano...
Gli operatori mobile italiani offrono se...
realme GT 8 Pro in promo lancio con 100€...
Autostrade, dal 2026 arrivano i rimborsi...
Carenza di memoria flash NAND e prezzi a...
EA Sports FC 26 fa felici i fan: tornano...
Anthropic studia i suoi ingegneri: l'IA ...
Kioxia Exceria Plus G4: l'SSD PCIe 5.0 p...
HBO Max debutta in Italia: data, contenu...
Qual è lo smartphone Android pi&u...
Il camion elettrico Semi è davver...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 16:41.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Served by www3v