Sign in to follow this  
The_Nerd

OpenGL I NEED HELP BAD!!!

Recommended Posts

Alright, I have a very weird texture problem. I build up the font characters for my GL print function. Each character is a little OpenGL list. Inside the list is the quad, and the texture bound to the quad. It's nice and compiled. Now when I print a string, everything works fine, every thing that is, except anything after the print function! For some reason, every polygon I render after the print function has the texture of the last character, no matter what I do (glDisable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2d); glBind(MY_BLOODY_TEXTURE_THAT_IS_NOT_THE_LAST_CHARACTER);). Also, calling glDeleteTextures on my glGenTextures list causes a SEGV at the end of the program. I got allot of code, so I just want to ask if you guys have any ideas before I start posting it.

Share this post


Link to post
Share on other sites
Quote:
Original post by The_Nerd
For some reason, every polygon I render after the print function has the texture of the last character, no matter what I do (glDisable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2d); glBind(MY_BLOODY_TEXTURE_THAT_IS_NOT_THE_LAST_CHARACTER);).


Yep, we're going to need to see some code before we can determine the problem. Could be a number of things. :)

Quote:
Also, calling glDeleteTextures on my glGenTextures list causes a SEGV at the end of the program.


I don't think glDeleteTextures is safe to call inside of a display list.

Quote:
I got allot of code, so I just want to ask if you guys have any ideas before I start posting it.


*braces self* Alright! Make sure you only post the relevant stuff, of course. :)

Share this post


Link to post
Share on other sites
Function to build a font character:

bool make_dlist (FT_Face Face, uint16 Ch, Ner3DFont *Fnt)
{
static Ner3DImage *TempImage=VID_NewImage();
if (!TempImage) return false;
if(FT_Load_Glyph(Face, FT_Get_Char_Index(Face, Ch), FT_LOAD_DEFAULT)) return false;

//Move the face's glyph into a Glyph object.
FT_Glyph Glyph;
if(FT_Get_Glyph(Face->glyph, &Glyph)) return false;

//Convert the glyph to a bitmap.
FT_Glyph_To_Bitmap(&Glyph, FT_RENDER_MODE_NORMAL, 0, 1 );
FT_BitmapGlyph Bitmap_Glyph = (FT_BitmapGlyph)Glyph;

//This reference will make accessing the bitmap easier
FT_Bitmap& Bitmap=Bitmap_Glyph->bitmap;

//Use our helper function to get the widths of
//the bitmap data that we will need in order to create
//our texture.
int16 uiWidth = next_p2(Bitmap.width);
int16 uiHeight = next_p2(Bitmap.rows);

//Allocate memory for the texture data.
GLubyte* Expanded_Data = new GLubyte[ 2 * uiWidth * uiHeight];

//Here we fill in the data for the expanded bitmap.
//Notice that we are using two channel bitmap (one for
//luminocity and one for alpha), but we assign
//both luminocity and alpha to the value that we
//find in the FreeType bitmap.
//We use the ?: operator so that value which we use
//will be 0 if we are in the padding zone, and whatever
//is the the Freetype bitmap otherwise.
for(uint16 uiJ=0;uiJ<uiHeight;uiJ++)
for(uint16 uiJJ=0;uiJJ<uiWidth;uiJJ++)
memset(&Expanded_Data[2*(uiJJ+uiJ*uiWidth)], (uiJJ>=Bitmap.width||uiJ>=Bitmap.rows)?0:Bitmap.buffer[uiJJ+Bitmap.width*uiJ], 2);

TempImage->New(uiWidth, uiHeight, 32);
memcpy(TempImage->Buffer, Expanded_Data, uiWidth*uiHeight*4);
TempImage->uiFlags=NER3D_IMG_CLAMPX|NER3D_IMG_CLAMPY;
TempImage->Bind(GL_RGBA, GL_LUMINANCE_ALPHA);


//With the texture created, we don't need to expanded data anymore
delete [] Expanded_Data;

//So now we can create the display list
glNewList(Fnt->uiListBase+Ch,GL_COMPILE);

//glBindTexture(GL_TEXTURE_2D,Fnt->uiTextureBase[Ch]);
VID_BindGLTexture(TempImage->iGLIndex);
TempImage->Free();

//first we need to move over a little so that
//the character has the right amount of space
//between it and the one before it.
glTranslatef(Bitmap_Glyph->left,0,0);

//Now we move down a little in the case that the
//bitmap extends past the bottom of the line
//(this is only true for characters like 'g' or 'y'.
glPushMatrix();
glTranslatef(0,(0-Bitmap_Glyph->top)+DEFAULT_CHAR_WIDTH,0);
//n3dDebug("%c = %d/%d", Ch, Bitmap_Glyph->top, Bitmap.rows);

//Now we need to account for the fact that many of
//our textures are filled with empty padding space.
//We figure what portion of the texture is used by
//the actual character and store that information in
//the x and y variables, then when we draw the
//quad, we will only reference the parts of the texture
//that we contain the character itself.
float32 fX=(float32)Bitmap.width/(float32)uiWidth,
fY=(float32)Bitmap.rows/(float32)uiHeight;

//Here we draw the texturemaped quads.
//The bitmap that we got from FreeType was not
//oriented quite like we would like it to be,
//so we need to link the texture to the quad
//so that the result will be properly aligned.
glBegin(GL_QUADS);
glTexCoord2d(0,0); glVertex2f(0,0);
glTexCoord2d(0,fY); glVertex2f(0,Bitmap.rows);
glTexCoord2d(fX,fY); glVertex2f(Bitmap.width,Bitmap.rows);
glTexCoord2d(fX,0); glVertex2f(Bitmap.width,0);
glEnd();
glPopMatrix();
glTranslatef(Face->glyph->advance.x >> 6 ,0,0);

//increment the raster position as if we were a bitmap font.
//(only needed if you want to calculate text length)
//glBitmap(0,0,0,0,face->glyph->advance.x >> 6,0,NULL);

//Finnish the display list
glEndList();
}
/*------------------------------------------------------------------------------------------------------------------*/



Ner3DImage::Bind() and Ner3DImage::New function:


GLuint uiGlobalTextureObject[IMG_MAX_TEXTURES];
static uint16 uiCurrentBoundTexture=0, uiTotalBoundTextures=0, uiBoundTextureIndex=0;
static list<Ner3DImage *> gImages;
FallBackTexture FallBackTex;
int16 iCurrentlyBoundTexture=-1;

/*------------------------------------------------------------------------------------------------------------------*/
bool Ner3DImage::Bind(GLint IFormat, GLint Format)
{
if (Buffer==NULL) return false;

if (this->iGLIndex!=-1)
{
uiCurrentBoundTexture=this->iGLIndex;
return true; //Already bound... just return
}

glBindTexture(GL_TEXTURE_2D, uiGlobalTextureObject[uiBoundTextureIndex]);
uiBoundTextureIndex++;

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (uiFlags&NER3D_IMG_CLAMPX)?GL_CLAMP:GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (uiFlags&NER3D_IMG_CLAMPY)?GL_CLAMP:GL_REPEAT);
if (uiFlags&NER3D_IMG_MIPMAPPED)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D,
IFormat,
(unsigned int)uiWidth,
(unsigned int)uiHeight,
Format,
GL_UNSIGNED_BYTE,
Buffer);
}
else
{
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D,
0,
IFormat,
(unsigned int)uiWidth,
(unsigned int)uiHeight,
0,
Format,
GL_UNSIGNED_BYTE,
Buffer);
}
iGLIndex=uiGlobalTextureObject[uiBoundTextureIndex-1]-1;
uiCurrentBoundTexture=uiGlobalTextureObject[uiBoundTextureIndex-1];
uiTotalBoundTextures++;
return true;
}
/*------------------------------------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------------------------------------------*/
bool Ner3DImage::New(uint16 uiWidth, uint16 uiHeight, uint16 uiBpp)
{
Free();
if (uiWidth>0&&uiHeight>0&&uiBpp>0)
{
Buffer=(RGBA_ARRAY *)realloc(Buffer, ((uiWidth*uiHeight)*uiBpp)*sizeof(RGBA_ARRAY));
if (Buffer==NULL) return false;
}
this->uiWidth=uiWidth;
this->uiHeight=uiHeight;
this->uiBpp=uiBpp;
return true;
}
/*------------------------------------------------------------------------------------------------------------------*/



Print function:

/*------------------------------------------------------------------------------------------------------------------*/
void VID_FontPrint(Ner3DFontInfo *Info, uchar8 *ucpStr)
{
if (Info->uiFont>=uiGFontCount) return;
Ner3DFont *CurrentFont=&tpFonts[Info->uiFont];
uint16 uiI, uiII, uiTab=0, uiJ, uiLayerCount;
float32 fCharWidth=(float32)DEFAULT_CHAR_SPACING*Info->Size.fX;
uchar8 *ucpPt, ucpTag[128]={0}, ucpValue[128]={0};
list<Ner3DMaterialLayer *>::iterator TempItr=NULL;
Ner3DImage *Char;

glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
//Info->Position.fX-=fCharWidth;

glPushMatrix();
glLoadIdentity();
glTranslatef(Info->Position.fX, Info->Position.fY, 0);

for (;ucpStr[0]!=0;uiTab++, ucpStr++)
{
if ((Info->uiFlags&FONT_FLAG_IGNORETAGS)==0)
{
if (ucpStr[0]=='[')
{
//ucpStr++;
if (ucpStr[1]!='['&&ucpStr[1]!=0)
{
for (ucpPt=&ucpStr[1], uiII=0;ucpPt[0]!=(uchar8)' '&&ucpPt[0]!=0;uiII++, ++ucpPt)
{
ucpTag[uiII]=ucpPt[0];
ucpTag[uiII+1]=0;
}
for (uiII=0;ucpPt[0]!=']'&&ucpPt[0]!=0;uiII++, ++ucpPt)
{
ucpValue[uiII]=ucpPt[0];
ucpValue[uiII+1]=0;
}
//n3dMessage("Tag %s value %s", ucpTag, ucpValue);
if (ucpPt[0]==']')
{
STR_SWITCH((char *)ucpTag)
{
STR_CASE("color")
{
sscanf((char *)ucpValue, "%f, %f, %f, %f", &Info->Color.fR, &Info->Color.fG, &Info->Color.fB, &Info->Color.fA);
break;
}
STR_CASE("tabwidth")
{
//sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue);
Info->uiTabWidth=atoi((char *)ucpValue);
break;
}
STR_CASE("i")
{
//sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue);
Info->uiFlags=(atoi((char *)ucpValue))?FONT_FLAG_ITALIC:0;
break;
}
STR_CASE("size")
{
//sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue);
Info->Size.fX=atof((char *)ucpValue);
Info->Size.fY=Info->Size.fX;
fCharWidth=DEFAULT_CHAR_SPACING*Info->Size.fX;
glScalef(Info->Size.fX, Info->Size.fY, 1);
break;
}
STR_CASE("sizex")
{
//sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue);
Info->Size.fX=atof((char *)ucpValue);
fCharWidth=DEFAULT_CHAR_SPACING*Info->Size.fX;
glScalef(Info->Size.fX, Info->Size.fY, 1);
break;
}
STR_CASE("sizey")
{
//sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue);
Info->Size.fY=atof((char *)ucpValue);
glScalef(Info->Size.fX, Info->Size.fY, 1);
break;
}
STR_CASE("xpos")
{
//sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue);
Info->Position.fX=(float32)atoi((char *)ucpValue);
glTranslatef(Info->Position.fX, 0, 0);
break;
}
STR_CASE("ypos")
{
//sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue);
Info->Position.fY=(float32)atoi((char *)ucpValue);
glTranslatef(0, Info->Position.fY, 0);
break;
}
STR_CASE("rotate")
{
//sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue);
Info->Rotation.fAngleZ=atof((char *)ucpValue);
break;
}
STR_CASE("rot")
{
//sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue);
Info->CRotation.fAngleZ=atof((char *)ucpValue);
break;
}
STR_CASE("font")
{
//sscanf((char *)ucpValue, "%d, %d, %d", &ucRed, &ucGreen, &ucBlue);
Info->uiFont=atoi((char *)ucpValue);
if (Info->uiFont>=uiGFontCount) Info->uiFont=uiGFontCount-1;
CurrentFont=&tpFonts[Info->uiFont];
break;
}
break;
}
ucpStr=ucpPt;
continue;
}
}
}
}

glColor4f(Info->Color.fR, Info->Color.fG, Info->Color.fB, Info->Color.fA);
glCallList(CurrentFont->uiListBase+ucpStr[0]);
}
glPopMatrix();
glColor3ub(255, 255, 255);
}
/*------------------------------------------------------------------------------------------------------------------*/



Misc classes:


class Ner3DFont
{
public:
uint16 uiListBase;
};

class Ner3DFontInfo
{
public:
Ner3DPoint2D Position;
Ner3DPoint2D Size;
Ner3DNormal Rotation;
Ner3DNormal CRotation;
Ner3DColor Color;
uint16 uiFlags, uiFont, uiTabWidth;

Ner3DFontInfo() { Reset(); }
void Reset(){
Position.fX=0.0;
Position.fY=0.0;
Size.fX=1.0;
Size.fY=1.0;
Rotation.fAngleZ=0.0;
CRotation.fAngleZ=0.0;
Color.fR=1.0;
Color.fG=1.0;
Color.fB=1.0;
Color.fA=1.0;
uiFlags=0;
uiFont=0;
uiTabWidth=4;
}
};




Anything else??? Don't say I didn't warn you! :)

[Edited by - The_Nerd on November 11, 2004 12:57:25 PM]

Share this post


Link to post
Share on other sites
>>For some reason, every polygon I render after the print function has the texture of the last character, no matter what I do (glDisable(GL_TEXTURE_2D);<<

did u disable ALL the texture units

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Announcements

  • Forum Statistics

    • Total Topics
      628328
    • Total Posts
      2982099
  • Similar Content

    • By mellinoe
      Hi all,
      First time poster here, although I've been reading posts here for quite a while. This place has been invaluable for learning graphics programming -- thanks for a great resource!
      Right now, I'm working on a graphics abstraction layer for .NET which supports D3D11, Vulkan, and OpenGL at the moment. I have implemented most of my planned features already, and things are working well. Some remaining features that I am planning are Compute Shaders, and some flavor of read-write shader resources. At the moment, my shaders can just get simple read-only access to a uniform (or constant) buffer, a texture, or a sampler. Unfortunately, I'm having a tough time grasping the distinctions between all of the different kinds of read-write resources that are available. In D3D alone, there seem to be 5 or 6 different kinds of resources with similar but different characteristics. On top of that, I get the impression that some of them are more or less "obsoleted" by the newer kinds, and don't have much of a place in modern code. There seem to be a few pivots:
      The data source/destination (buffer or texture) Read-write or read-only Structured or unstructured (?) Ordered vs unordered (?) These are just my observations based on a lot of MSDN and OpenGL doc reading. For my library, I'm not interested in exposing every possibility to the user -- just trying to find a good "middle-ground" that can be represented cleanly across API's which is good enough for common scenarios.
      Can anyone give a sort of "overview" of the different options, and perhaps compare/contrast the concepts between Direct3D, OpenGL, and Vulkan? I'd also be very interested in hearing how other folks have abstracted these concepts in their libraries.
    • By aejt
      I recently started getting into graphics programming (2nd try, first try was many years ago) and I'm working on a 3d rendering engine which I hope to be able to make a 3D game with sooner or later. I have plenty of C++ experience, but not a lot when it comes to graphics, and while it's definitely going much better this time, I'm having trouble figuring out how assets are usually handled by engines.
      I'm not having trouble with handling the GPU resources, but more so with how the resources should be defined and used in the system (materials, models, etc).
      This is my plan now, I've implemented most of it except for the XML parts and factories and those are the ones I'm not sure of at all:
      I have these classes:
      For GPU resources:
      Geometry: holds and manages everything needed to render a geometry: VAO, VBO, EBO. Texture: holds and manages a texture which is loaded into the GPU. Shader: holds and manages a shader which is loaded into the GPU. For assets relying on GPU resources:
      Material: holds a shader resource, multiple texture resources, as well as uniform settings. Mesh: holds a geometry and a material. Model: holds multiple meshes, possibly in a tree structure to more easily support skinning later on? For handling GPU resources:
      ResourceCache<T>: T can be any resource loaded into the GPU. It owns these resources and only hands out handles to them on request (currently string identifiers are used when requesting handles, but all resources are stored in a vector and each handle only contains resource's index in that vector) Resource<T>: The handles given out from ResourceCache. The handles are reference counted and to get the underlying resource you simply deference like with pointers (*handle).  
      And my plan is to define everything into these XML documents to abstract away files:
      Resources.xml for ref-counted GPU resources (geometry, shaders, textures) Resources are assigned names/ids and resource files, and possibly some attributes (what vertex attributes does this geometry have? what vertex attributes does this shader expect? what uniforms does this shader use? and so on) Are reference counted using ResourceCache<T> Assets.xml for assets using the GPU resources (materials, meshes, models) Assets are not reference counted, but they hold handles to ref-counted resources. References the resources defined in Resources.xml by names/ids. The XMLs are loaded into some structure in memory which is then used for loading the resources/assets using factory classes:
      Factory classes for resources:
      For example, a texture factory could contain the texture definitions from the XML containing data about textures in the game, as well as a cache containing all loaded textures. This means it has mappings from each name/id to a file and when asked to load a texture with a name/id, it can look up its path and use a "BinaryLoader" to either load the file and create the resource directly, or asynchronously load the file's data into a queue which then can be read from later to create the resources synchronously in the GL context. These factories only return handles.
      Factory classes for assets:
      Much like for resources, these classes contain the definitions for the assets they can load. For example, with the definition the MaterialFactory will know which shader, textures and possibly uniform a certain material has, and with the help of TextureFactory and ShaderFactory, it can retrieve handles to the resources it needs (Shader + Textures), setup itself from XML data (uniform values), and return a created instance of requested material. These factories return actual instances, not handles (but the instances contain handles).
       
       
      Is this a good or commonly used approach? Is this going to bite me in the ass later on? Are there other more preferable approaches? Is this outside of the scope of a 3d renderer and should be on the engine side? I'd love to receive and kind of advice or suggestions!
      Thanks!
    • By nedondev
      I 'm learning how to create game by using opengl with c/c++ coding, so here is my fist game. In video description also have game contain in Dropbox. May be I will make it better in future.
      Thanks.
    • By Abecederia
      So I've recently started learning some GLSL and now I'm toying with a POM shader. I'm trying to optimize it and notice that it starts having issues at high texture sizes, especially with self-shadowing.
      Now I know POM is expensive either way, but would pulling the heightmap out of the normalmap alpha channel and in it's own 8bit texture make doing all those dozens of texture fetches more cheap? Or is everything in the cache aligned to 32bit anyway? I haven't implemented texture compression yet, I think that would help? But regardless, should there be a performance boost from decoupling the heightmap? I could also keep it in a lower resolution than the normalmap if that would improve performance.
      Any help is much appreciated, please keep in mind I'm somewhat of a newbie. Thanks!
    • By test opty
      Hi,
      I'm trying to learn OpenGL through a website and have proceeded until this page of it. The output is a simple triangle. The problem is the complexity.
      I have read that page several times and tried to analyse the code but I haven't understood the code properly and completely yet. This is the code:
       
      #include <glad/glad.h> #include <GLFW/glfw3.h> #include <C:\Users\Abbasi\Desktop\std_lib_facilities_4.h> using namespace std; //****************************************************************************** void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); // settings const unsigned int SCR_WIDTH = 800; const unsigned int SCR_HEIGHT = 600; const char *vertexShaderSource = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" "void main()\n" "{\n" " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n" "}\0"; const char *fragmentShaderSource = "#version 330 core\n" "out vec4 FragColor;\n" "void main()\n" "{\n" " FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" "}\n\0"; //******************************* int main() { // glfw: initialize and configure // ------------------------------ glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // glfw window creation GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "My First Triangle", nullptr, nullptr); if (window == nullptr) { cout << "Failed to create GLFW window" << endl; glfwTerminate(); return -1; } glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); // glad: load all OpenGL function pointers if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { cout << "Failed to initialize GLAD" << endl; return -1; } // build and compile our shader program // vertex shader int vertexShader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vertexShader, 1, &vertexShaderSource, nullptr); glCompileShader(vertexShader); // check for shader compile errors int success; char infoLog[512]; glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success); if (!success) { glGetShaderInfoLog(vertexShader, 512, nullptr, infoLog); cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << endl; } // fragment shader int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragmentShader, 1, &fragmentShaderSource, nullptr); glCompileShader(fragmentShader); // check for shader compile errors glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success); if (!success) { glGetShaderInfoLog(fragmentShader, 512, nullptr, infoLog); cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << endl; } // link shaders int shaderProgram = glCreateProgram(); glAttachShader(shaderProgram, vertexShader); glAttachShader(shaderProgram, fragmentShader); glLinkProgram(shaderProgram); // check for linking errors glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success); if (!success) { glGetProgramInfoLog(shaderProgram, 512, nullptr, infoLog); cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << endl; } glDeleteShader(vertexShader); glDeleteShader(fragmentShader); // set up vertex data (and buffer(s)) and configure vertex attributes float vertices[] = { -0.5f, -0.5f, 0.0f, // left 0.5f, -0.5f, 0.0f, // right 0.0f, 0.5f, 0.0f // top }; unsigned int VBO, VAO; glGenVertexArrays(1, &VAO); glGenBuffers(1, &VBO); // bind the Vertex Array Object first, then bind and set vertex buffer(s), //and then configure vertex attributes(s). glBindVertexArray(VAO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); glEnableVertexAttribArray(0); // note that this is allowed, the call to glVertexAttribPointer registered VBO // as the vertex attribute's bound vertex buffer object so afterwards we can safely unbind glBindBuffer(GL_ARRAY_BUFFER, 0); // You can unbind the VAO afterwards so other VAO calls won't accidentally // modify this VAO, but this rarely happens. Modifying other // VAOs requires a call to glBindVertexArray anyways so we generally don't unbind // VAOs (nor VBOs) when it's not directly necessary. glBindVertexArray(0); // uncomment this call to draw in wireframe polygons. //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // render loop while (!glfwWindowShouldClose(window)) { // input // ----- processInput(window); // render // ------ glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); // draw our first triangle glUseProgram(shaderProgram); glBindVertexArray(VAO); // seeing as we only have a single VAO there's no need to // bind it every time, but we'll do so to keep things a bit more organized glDrawArrays(GL_TRIANGLES, 0, 3); // glBindVertexArray(0); // no need to unbind it every time // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) glfwSwapBuffers(window); glfwPollEvents(); } // optional: de-allocate all resources once they've outlived their purpose: glDeleteVertexArrays(1, &VAO); glDeleteBuffers(1, &VBO); // glfw: terminate, clearing all previously allocated GLFW resources. glfwTerminate(); return 0; } //************************************************** // process all input: query GLFW whether relevant keys are pressed/released // this frame and react accordingly void processInput(GLFWwindow *window) { if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); } //******************************************************************** // glfw: whenever the window size changed (by OS or user resize) this callback function executes void framebuffer_size_callback(GLFWwindow* window, int width, int height) { // make sure the viewport matches the new window dimensions; note that width and // height will be significantly larger than specified on retina displays. glViewport(0, 0, width, height); } As you see, about 200 lines of complicated code only for a simple triangle. 
      I don't know what parts are necessary for that output. And also, what the correct order of instructions for such an output or programs is, generally. That start point is too complex for a beginner of OpenGL like me and I don't know how to make the issue solved. What are your ideas please? What is the way to figure both the code and the whole program out correctly please?
      I wish I'd read a reference that would teach me OpenGL through a step-by-step method. 
  • Popular Now