Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Jabra Evolve3 85: le cuffie sia per l'intrattenimento che per il lavoro
Jabra Evolve3 85: le cuffie sia per l'intrattenimento che per il lavoro
Le Jabra Evolve3 85 non sono semplicemente cuffie Bluetooth con cancellazione del rumore. Sono un dispositivo professionale pensato per chi trascorre gran parte della giornata in riunione, al telefono o davanti a un assistente basato sull'intelligenza artificiale
MSI PRO MAX EDGE AI+, Ryzen AI Max+ 395 e 128 GB per far girare in locale anche i modelli più grandi
MSI PRO MAX EDGE AI+, Ryzen AI Max+ 395 e 128 GB per far girare in locale anche i modelli più grandi
Abbiamo provato MSI PRO MAX EDGE AI+, un mini-PC professionale progettato per eseguire modelli di intelligenza artificiale in locale, senza dipendere dal cloud. Il sistema abbina il processore AMD Ryzen AI Max+ 395, 128 GB di memoria unificata e un telaio in alluminio da appena 4 litri, con l'obiettivo di offrire capacità di elaborazione elevate in un formato compatto.
Recensione vivo X500 Pro Max: la fotografia mobile ha un nuovo protagonista
Recensione vivo X500 Pro Max: la fotografia mobile ha un nuovo protagonista
Il nuovo top di gamma vivo punta su un comparto fotografico particolarmente articolato, con un teleobiettivo da 200 megapixel e teleconvertitori esterni capaci di arrivare a 400 mm equivalenti. Lo abbiamo provato a Tenerife, mettendo alla prova fotocamere, prestazioni, autonomia e accessori. Ecco come si è comportato.
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 13-12-2013, 13:17   #1
-Ivan-
Senior Member
 
L'Avatar di -Ivan-
 
Iscritto dal: Mar 2003
Città: Rimini
Messaggi: 1846
[OpenGL] Esercizio per disegnare un cubo mostra solo la faccia frontale

Sto facendo un esercizio in cui cerco di disegnare un cubo con OpenGL.
Non riesco a capire perchè mi mostri solo la faccia frontale.
Per disegnarlo uso glDrawElements dopo aver creato un buffer di indici ed il buffer con i vertici del cubo.

Codice:
// include...


enum Attrib_IDs { vPosition = 0 };

GLuint VERTEX_SHADER_ID;

GLuint VBOs[1];		// Vertex Buffer Objects
GLuint IBOs[1];		// Index Buffer Objects

GLuint SCREEN_WIDTH = 512, SCREEN_HEIGHT = 512;

glm::mat4 mvp;		//model view projection matrix



#pragma region INITIALIZE DATA AND OPENGL

void ModelViewProjectionMatrix()
{
	// Matrix to translate the cube deep far in the scene
	glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3(0.0, 0.0, -4.0));

	// The lookat function takes: eye (position of the camera), center (where the camera is pointed to), and up (top of the camera).
	glm::mat4 view = glm::lookAt(glm::vec3(0.0, 2.0, 0.0), glm::vec3(0.0, 0.0, -4.0), glm::vec3(0.0, 1.0, 0.0));

	// The perpective function takes: fovy (the lens angle), aspect (the aspect ratio), and zNear, zFar (clipping planes).
	glm::mat4 projection = glm::perspective(45.0f, 1.0f * SCREEN_WIDTH/SCREEN_HEIGHT, 0.1f, 10.0f);


	// We end up with a model view projection matrix giving us the result for our camera
	mvp = projection * view * model;
}

void CreateVerticesData()
{
	Vector3D cube_vertices[] = {
		// front
		Vector3D(-1.0, -1.0,  1.0),
		Vector3D( 1.0, -1.0,  1.0),
		Vector3D( 1.0,  1.0,  1.0),
		Vector3D(-1.0,  1.0,  1.0),
		// back
		Vector3D(-1.0, -1.0, -1.0),
		Vector3D( 1.0, -1.0, -1.0),
		Vector3D( 1.0,  1.0, -1.0),
		Vector3D(-1.0,  1.0, -1.0)
	};

	// Generate the Vertex Buffer Object storing the data for the 8 vertices of the cube.
	// In total there are 24 floats representing the x, y, z components of each vertex.
	glGenBuffers(1, VBOs);
	glBindBuffer(GL_ARRAY_BUFFER, VBOs[0]);
	glBufferData(GL_ARRAY_BUFFER, sizeof(cube_vertices), cube_vertices, GL_STATIC_DRAW);
}

void CreateIndexData()
{
	// Indices of the vertices of the cube.
	// This is used to avoid duplicates. As the faces of the cube share vertices we can duplicate this vertices ending with a
	// total of 36 (6 faces x 2 triangles per face x 3 vertices each triangle = 36) or we can store them just once and refer to them
	// using these indices and drawing the cube with glDrawElements instead than with glDrawArray that just iterates through an array
	// drawing every vertices it finds in it.
	GLushort cube_elements[] = {
		// front
		0, 1, 2,
		2, 3, 0,
		// top
		3, 2, 6,
		6, 7, 3,
		// back
		7, 6, 5,
		5, 4, 7,
		// bottom
		4, 5, 1,
		1, 0, 4,
		// left
		4, 0, 3,
		3, 7, 4,
		// right
		1, 5, 6,
		6, 2, 1,
	};

	// Generate the Index Buffer Object to index the vertices inside the Vertex Buffer Object.
	// The indexes are related to the 8 vertices making the cube.
	glGenBuffers(1, IBOs);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBOs[0]);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(cube_elements), cube_elements, GL_STATIC_DRAW);
}

void Init()
{
	glEnable(GL_DEPTH_TEST);
	ModelViewProjectionMatrix();

	CreateVerticesData();
	CreateIndexData();

	// Load and use the shaders
	VERTEX_SHADER_ID = LoadShader("shader.vert", "shader.frag");
	glUseProgram(VERTEX_SHADER_ID);

	// Set up the value of the uniform value inside the vertex shader
	GLuint mvp_Loc = glGetUniformLocation(VERTEX_SHADER_ID, "mvp");
	glUniformMatrix4fv(mvp_Loc, 1, GL_FALSE, glm::value_ptr(mvp));

	// Defines parameters to pass to the shaders
	glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
	glEnableVertexAttribArray(vPosition);
}

#pragma endregion

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

	int size;
	glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBOs[0]);
	glDrawElements(GL_TRIANGLES, size / sizeof(GLushort), GL_UNSIGNED_SHORT, 0);

	// marks the current window as needing to be redisplayed
    glutPostRedisplay();
	glFlush();
}

int _tmain(int argc, _TCHAR* argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA);
	glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT);
	glutInitContextVersion(3, 3);
	glutInitContextProfile(GLUT_CORE_PROFILE);
	glutCreateWindow("Cube");

	if( glewInit() )
	{
		std::cerr << "Error...exiting";
		exit(EXIT_FAILURE);
	}

	Init();

	glutDisplayFunc(Display);
	glutMainLoop();

	return 0;
}
-Ivan- è offline   Rispondi citando il messaggio o parte di esso
Old 13-12-2013, 16:24   #2
-Ivan-
Senior Member
 
L'Avatar di -Ivan-
 
Iscritto dal: Mar 2003
Città: Rimini
Messaggi: 1846
Ho trovato.
L'errore era in:
Codice:
glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
che invece deve essere:

Codice:
glVertexAttribPointer(vPosition, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
Stavo ignorando l'asse Z. Purtroppo avevo copiato quella riga da un altro esercizio in cui disegnavo un triangolo e quindi avevo coordinate su due dimensioni.
-Ivan- è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Jabra Evolve3 85: le cuffie sia per l'intrattenimento che per il lavoro Jabra Evolve3 85: le cuffie sia per l'intratteni...
MSI PRO MAX EDGE AI+, Ryzen AI Max+ 395 e 128 GB per far girare in locale anche i modelli più grandi MSI PRO MAX EDGE AI+, Ryzen AI Max+ 395 e 128 GB...
Recensione vivo X500 Pro Max: la fotografia mobile ha un nuovo protagonista Recensione vivo X500 Pro Max: la fotografia mobi...
WoW Forever: la beta è stato uno dei momenti più alti della storia dei videogiochi, e non si ripeterà WoW Forever: la beta è stato uno dei mome...
Oracle AI World 2026: in Europa prima la sovranità, poi la sicurezza e solo dopo l'IA Oracle AI World 2026: in Europa prima la sovrani...
Nintendo Switch 2: nessun aumento di pre...
GeForce 8800 GTX, vent'anni dopo: NVIDIA...
GPT-6 Cyber, OpenAI presenta il modello ...
iPhone: il redesign dei 20 anni sarà inn...
OpenAI sfida GitHub acquisendo Pierre Co...
Novità ai vertici di HP: Emma Wal...
Pudu Robotics apre la sede europea : un ...
Meta compra Conductor, la startup degli ...
ASUS ExpertBook A7: disponibile in Itali...
Il film di Naruto si farà davvero: Sony ...
Motorola porta il suono Bose su moto bud...
Motorola presenta moto watch 2 fit: tecn...
motorola signature 27 ufficiale! Il top ...
Dreame L60 Ultra CE a 799€ su Amazon: 35...
DJI Matrice 5T: nuovo drone enterprise c...
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: 03:02.


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