Author Topic: OpenGL - Some questions  (Read 3875 times)

0 Members and 1 Guest are viewing this topic.

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
OpenGL - Some questions
« on: March 23, 2007 »
1)
i am using glVertex2() to draw a box with gradient that should looks something like a copperbar.

Code: [Select]
000   < Border Color
111
222
333   < Inside Coloe
222
111
000  < Border Color

I am doing it in PB using something like this: (just example code)

Code: [Select]
  glBegin_(#GL_QUADS); // Draw A Quad

    glColor3f_ (207/255, 207/255, 0)
glVertex2f_(  0,  510); //
glVertex2f_(800,  510); // Top Right
;
glColor3f_ (255/255, 154/255, 0)
glVertex2f_(800, 510); // Bottom Right
glVertex2f_(  0, 510); // Bottom Left
    ; -----
    glColor3f_ (207/255, 154/255, 0)
  glVertex2f_(  0, 507); //
  glVertex2f_(800, 507); // Top Right
  ;
  glColor3f_ (255/255, 207/255, 0)
  glVertex2f_(800, 3+507); // Bottom Right
  glVertex2f_(  0, 3+507); // Bottom Left
glEnd_();

As you can see, i am using and drawing 2 rects.. is there any other (smaller/better) OGL API or way to realise this?



2)
For example when using topic example for drawing a rect... is this a good way for drawing a copperbar for example or would it be back drawing it this way?



i am sure, some more OGL related questions will follow soon ^^ thx
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: OpenGL - Some questions
« Reply #1 on: March 23, 2007 »
Better ways of doing it mean either drawing lots and lots of copper bars between one pair of glBegin/glEnd or to create a vertex buffer to do lots or to create a display list to do lots - in that order.  If you're only drawing one bar, then what you are doing is close to optimal.

Happy to answer lots of questions!

Jim
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: OpenGL - Some questions
« Reply #2 on: March 23, 2007 »
ok thanks... i dont worked with display list yet... btw, creating the copperbar gradient box is only possible with 8x glVertex2f() instead any way to use only 6x glVertex2f(), right?

whats the best (smalltest) code for displaying bitmap font text and doing sinusscroller? ^^

For example when i want create and use an own at runtime generated image or texture to display... whats the best way for handling this image? Is there a way to draw direct on an OGL texture using OGL? Or do i must create a Bitmap with the API, draw on this just by peeking/poking values into its memory area and catch this created BMP image with OGL? (the needed code should be as small as possible... thanks in advance)
« Last Edit: March 23, 2007 by va!n »
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: OpenGL - Some questions
« Reply #3 on: March 23, 2007 »
You can do it in 6 with a triangle strip.

Here's the code from ps2yabasic for doing Windows fonts.
Code: [Select]
#include <windows.h>
#include <gl\gl.h>
GLuint m_iFontBase;
void BuildFont(HDC m_hDC)
{
m_iFontBase = glGenLists(255);

font = CreateFont(
17, // h
11, // w
0,
0,
FW_BOLD,
FALSE,
FALSE,
FALSE,
ANSI_CHARSET,
OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
FF_DONTCARE | FIXED_PITCH,
"Courier New"
);

orig_font=SelectObject(m_hDC, font);

wglUseFontBitmaps(m_hDC, 0, 255, m_iFontBase);
return;
}

void PS2_draw_Text(int RGB, int x, int y, const char *pText)
{
glRasterPos2i(x, y);

glPushAttrib(GL_LIST_BIT);

glListBase(m_iFontBase);

glCallLists(strlen(pText), GL_UNSIGNED_BYTE, pText);

glPopAttrib();
}

void DestroyFont(void)
{
glDeleteLists(m_iFontBase, 255);
}
I thnk that's it, I just snipped it from a load of surrounding code.

You could also use glDrawImage() which can be very slow, depending on your card/driver or you could use a texture with a font drawn in it and use quads to draw the letters - but as you say, you need to manage all that yourself.  It's defintiely possible to render-to-texture using OpenGL too.

Jim
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: OpenGL - Some questions
« Reply #4 on: March 23, 2007 »
There's one example of how to display 2D bitmap font here -> http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=17

Why not drawing that copperbar using glLines ? If you look closely to what Shockwave did, you will see that it's only lines, you just need to change the colors properly to make that effect.

Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: OpenGL - Some questions
« Reply #5 on: March 26, 2007 »
@Jim:
Thanks for the codesnip... i ported it to PB and it works very well...

@rbraz:
Thanks... i will take a closer look to it..
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won: