Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Un fulmine sulla scrivania, Corsair Sabre v2 Pro ridefinisce la velocità nel gaming
Un fulmine sulla scrivania, Corsair Sabre v2 Pro ridefinisce la velocità nel gaming
Questo mouse ultraleggero, con soli 36 grammi di peso, è stato concepito per offrire un'esperienza di gioco di alto livello ai professionisti degli FPS, grazie al polling rate a 8.000 Hz e a un sensore ottico da 33.000 DPI. La recensione esplora ogni dettaglio di questo dispositivo di gioco, dalla sua agilità estrema alle specifiche tecniche che lo pongono un passo avanti
Nokia Innovation Day 2025: l’Europa ha bisogno di campioni nelle telecomunicazioni
Nokia Innovation Day 2025: l’Europa ha bisogno di campioni nelle telecomunicazioni
Dal richiamo di Enrico Letta alla necessità di completare il mercato unico entro il 2028 alla visione di Nokia sul ruolo dell’IA e delle reti intelligenti, il Nokia Innovation Day 2025 ha intrecciato geopolitica e tecnologia, mostrando a Vimercate come la ricerca italiana contribuisca alle sfide globali delle telecomunicazioni
Sottile, leggero e dall'autonomia WOW: OPPO Reno14 F conquista con stile e sostanza
Sottile, leggero e dall'autonomia WOW: OPPO Reno14 F conquista con stile e sostanza
OPPO Reno14 F 5G si propone come smartphone di fascia media con caratteristiche equilibrate. Il device monta processore Qualcomm Snapdragon 6 Gen 1, display AMOLED da 6,57 pollici a 120Hz, tripla fotocamera posteriore con sensore principale da 50MP e generosa batteria da 6000mAh con ricarica rapida a 45W. Si posiziona come alternativa accessibile nella gamma Reno14, proponendo un design curato e tutto quello che serve per un uso senza troppe preoccupazioni.
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 30-03-2005, 11: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, 15: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, 17: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, 18: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, 20: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, 20: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, 20: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 31-03-2005, 23: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 : 31-03-2005 alle 23:12.
AnonimoVeneziano è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Un fulmine sulla scrivania, Corsair Sabre v2 Pro ridefinisce la velocità nel gaming Un fulmine sulla scrivania, Corsair Sabre v2 Pro...
Nokia Innovation Day 2025: l’Europa ha bisogno di campioni nelle telecomunicazioni Nokia Innovation Day 2025: l’Europa ha bisogno d...
Sottile, leggero e dall'autonomia WOW: OPPO Reno14 F conquista con stile e sostanza Sottile, leggero e dall'autonomia WOW: OPPO Reno...
Destiny Rising: quando un gioco mobile supera il gioco originale Destiny Rising: quando un gioco mobile supera il...
Plaud Note Pro convince per qualità e integrazione, ma l’abbonamento resta un ostacolo Plaud Note Pro convince per qualità e int...
Tamron 25-200mm F/2.8-5.6 Di III VXD G2:...
Il rover NASA VIPER arriverà sull...
Il MagSafe Battery Pack ha la stessa bat...
Il tri-fold di Samsung sta arrivando e s...
Prezzi a picco su Amazon nel weekend: 25...
6 accessori Amazon per pulire in maniera...
Tesla riprogetterà le sue iconich...
iPhone 17 Pro e Pro Max, eccoli tutti su...
Amazon abbatte il prezzo: scopa elettric...
Super sconti Amazon: 5 ottimi smartphone...
iPhone Air non è solo sottile: &e...
Energia in Italia ad agosto: consumi in ...
SpaceX guarda ai primi voli orbitali del...
Il prototipo del razzo spaziale riutiliz...
Blue Origin mostra uno spettacolare vide...
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: 15:46.


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