You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
glBegin(tipo_primitiva) // tipo_primitiva puede ser GL_TRIANGLES, GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP// Escribir sucesión de atributos del vértice + vértice. Ejemplo:
glColor3f(r1, g1, b1); glNormal(xn1, yn1, zn1); glTexCoord2f(u1, v1); glVertex3f(x1, y1, z1);
// glColor3f(), glNormal(), glTexCoord2f() pueden ser omitidos.
...
glColor3f(rn, gn, bn); glNormal(xnn, ynn, znn); glTexcoord2f(un, vn); glVertex3f(xn, yn, zn);
glEnd()
Uso del modo inmediato con Drawarrays / Drawelements
glEnableClientState(GL_VERTEX_ARRAY);
glBindVertexArray(0);
glVertexPointer(num_val_tupla, GL_FLOAT, 0, vertices.data());
// Si no hay indicesglDrawArrays(tipo_prim, 0, vertices.size());
//Si hay indicesglDrawElements(tipo_prim, indices.size(), GL_INT, 0);
glDrawElements(tipo_prim, indices.size(), GLuint, indices->datos);
// tipo_prim puede valer GL_POLYGON, GL_QUADS, GL_TRIANGLES, GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP, GL_TRIANGLE_STRIP, GL_QUAD_STRIP, GL_TRIANGLE_FANglDisableClientState(GL_VERTEX_ARRAY);
Generación y uso de VAO y VBO
// 1. Generate VBO if it does not exist (stores in VRAM)
GLuint VBO;
glGenBuffers(1, &VBO);
// 2. Generate VAO if it does not exist (in order to refer the VBO)
GLuint VAO;
glGenVertexArrays(1, &VAO);
// 3. Generate index table if neededunsignedint EBO;
glGenBuffers(1, &EBO);
// 4. bind Vertex Array ObjectglBindVertexArray(VAO);
// 5. copy our vertices array in a buffer for OpenGL to useglBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// 6. copy our index array (if it is not empty) in a element buffer for OpenGL to useglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
// 7. then set our vertex attributes pointersglVertexPointer(3, GL_FLOAT, 0, ptr_offset = 0);
// Alternatively, use glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);glEnableClientState(GL_VERTEX_ARRAY) //glEnableVertexAttribArray(0);// Keep in mind you don't need to generate the VAO or the VBO if you already had them. You should always try to reuse them.// [...]// ..:: Drawing code (in render loop) :: ..// 8. draw the object
glBindVertexArray(VAO);
someOpenGLFunctionThatDrawsOurTriangle();
// e.g. : glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0)glBindVertexArray(0);
mode Especifica qué primitivas se van a dibujar: GL_POINTS, GL_LINE_STRIP GL_LINE_LOOP, GL_LINES, GL_LINE_STRIP_ADJACENCY, GL_LINES_ADJACENCY, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_TRIANGLES, GL_TRIANGLE_STRIP_ADJACENCY, o GL_PATCHES
count Número de elementos que se van a dibujar
type Tipo de los indices ( GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, o GL_UNSIGNED_INT)
indices Puntero al vector donde están los índices almacenados.
voidcargartextura(imagen.jpog){
imagen = LeerArchivoJPEG(imagen.c_str() , ancho, alto);
GLUint idtex;
glGenTextures(1, &idtex);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, idtex);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); //Parametros de textura//Envio a GPUgluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGB, ancho, alto, GL_RGB, GL_UNSIGNED_BYTE, imagen);
// textura 2d, formato interno, núm. de columnas (arbitrario) (GLsizei), núm de filas (arbitrario) (GLsizei), formato y orden de los texels en RAM, tipo de cada componente de cada texel,puntero a los bytes con texels
}
Ejemplo de iluminación
void esfera_iluminada_colorverde_brillos_amarillos{
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
constfloat caf[4] = {r,g,b,1.0}, // color ambiental de la fuente
cdf[4] = {r,g,b,1.0}, // color difuso de la fuente
csf[4] = {r,g,b,1.0}; // color pseudoespecular de la fuente
caf = verde;
csf = amarillo;
glLightfv(GL_LIGHT0, GL_AMBIENT, caf);
glLightfv(GL_LIGHT0, GL_DIFFUSE, cdf); // No hace falta; no hay color fijoglLightfv(GL_LIGHT0, GL_SPECULAR, csf);
const GLfloat dirf[4] = { 1.0, 1.0, 1.0 , 0.0 } ; // dirección de la luz posicional (0 => dirección, 1 => posición)glLightfv( GL_LIGHT0, GL_POSITION, dirf ); // hacemos la luz posicional con direccionglLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE ); // GL_FALSE => posicionada en el infinito, GL_TRUE => local//glShadeModel(GL_SMOOTH);
}