GLFW介绍

GLFW介绍,第1张

官网: https://www.glfw.org/

是OpenGL的一个地方方苦,支持OpenGL、ES、Vulkan,支持多窗口高DPI 和gamma ramps,支持常用外设。开源用C实现的,要用zlib和libpng库。

首先包含头头文件

在glfw使用之前先要出世,初始化只要是检查环境是不是支持。

GLFWAPI int glfwInit(void)

初始化GLFW库,在应用称许执行之前要先调用这个函数,对应的终止函数是glfwTerminate,在应用程序结束之前要调用glfwTerminate,成功返回GLFW_TRUE

GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun callback)

设置错误回调函数,当一个错误发生时回调用错误码和一段描述信息。回调函数的个是如下:

GLFWAPI void glfwWindowHint(int hint, int value)

GLFWAPI void glfwWindowHintString(int hint, const char* value)

设置window的hints值,在glfwCreatewindow时生效,设置之后不会改变,知道遇到函数glfwDefaultWindowHints或GLFW终止。这个函数只能设置整形值,字符串的值通过glfwWindowHintString来设置。另外它不检查设置的值是否有效,在glfwCreateWindow的时候才会报.

GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share)

创建GL/ES的上下文,参数指定了上下文如何创建,成功创建不影响当前上下文。

GLFWAPI void glfwMakeContextCurrent(GLFWwindow* window)

指定当前GL/ES上下文

GLFWAPI int glfwWindowShouldClose(GLFWwindow* window)

检查指定window的关闭状态.

先银亏设置事件回调函数,输入事件比较多。

渲染的时候framebuffer的size可以设置和viewport一样大,也可以设置framebuffer size的回调函数。

GLFWAPI double glfwGetTime(void)

获取锋旅神GLFW的时间,以秒为单位

GLFWAPI void glfwSetTime(double time)

设置GLFW的时间,以秒为单位,小于等于18446744073.0

GLFWAPI uint64_t glfwGetTimerValue(void)

获取raw timer的值,单位1 / frequency seconds

GLFWAPI uint64_t glfwGetTimerFrequency(void)

获取帧率单位是Hz

GLFWAPI void glfwSwapBuffers(GLFWwindow* window)

交换窗口的前后缓冲区,如果交换间隔大于0,交换缓冲区之前GPU驱动会等待specified number of screen updates

GLFWAPI void glfwSwapInterval(int interval)

设置当前上下文的交换间隔

有两种处理未决事件的方法; 轮询和等待。

GLFWAPI void glfwPollEvents(void)

处理所有事件队列中的事件,事件处理会调用一些回调函数。一些平台下,窗口移动、镇做resize和菜单 *** 作都会触发事件处理,block当前的任务。

GLFWAPI void glfwWaitEvents(void)

等待所有处理中和队列中的事件完成,当前线程会进入sleep状态,如果有事件可用,就相当与glfwPollEvents.

GLFWAPI void glfwTerminate(void)

这个函数终止GLFW,这个函数会注销调剩余的windows and cursors,复位所有修改过的gamma ramps,释放申请的资源。对应glfwInit

GLFWAPI void glfwInitHint(i

nt hint, int value)

设置制定的初始化hint值,这个设置之后中间不能进行修改直至结束。有些hints是平台相关,这些只有在对应的平台上才会生效。

GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev)

查询GLFW库的版本,major, minor and revision号

GLFWAPI const char* glfwGetVersionString(void)

查询编译阶段的配置,返回的是个字符串,包含版本、平台、编译器和平台相关的编译阶段的选项

GLFWAPI int glfwGetError(const char** description)

查询错误码并清除上一次的错误信息

GLFWAPI GLFWmonitor** glfwGetMonitors(int* count)

查询当前的连接监视器connected monitors,返回的是当前所有连接的monitor,primary monitor永远是数组的第一个。

GLFWAPI GLFWmonitor* glfwGetPrimaryMonitor(void)

查询primary monitor,task bar和global menu bar等基本信息都是显示在primary monitor中的。

GLFWAPI void glfwGetMonitorPos(GLFWmonitor* monitor, int* xpos, int* ypos)

获取虚拟屏幕中monitor的视口坐标

GLFWAPI void glfwGetMonitorWorkarea(GLFWmonitor* monitor, int* xpos, int* ypos, int* width, int* height)

获取monitor的工作区,返回的是屏幕坐标的位置,左上角和size的值。工作区是屏幕中没有系统任务条的区域,如果系统没有任务条,就是全屏幕。

GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* monitor, int* widthMM, int* heightMM)

获取monitor的物理尺寸,单位是millimetres

GLFWAPI void glfwGetMonitorContentScale(GLFWmonitor* monitor, float* xscale, float* yscale)

获取monitor的content scale,这个值的计算:当前DPI与平台默认DPI之间的比。依赖于monitor的分辨率和设置的像素密度。

GLFWAPI const char* glfwGetMonitorName(GLFWmonitor* monitor)

获取monitor的名称

GLFWAPI void glfwSetMonitorUserPointer(GLFWmonitor* monitor, void* pointer)

设置monitor中用户自定义的pointer

GLFWAPI void* glfwGetMonitorUserPointer(GLFWmonitor* monitor)

获取monitor的用户自定义pointer

GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* monitor, int* count)

获取monitor的可用视频模式,返回的是一个数组,按照升序排列。

GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* monitor)

获取monitor的当前的视频模式,如果是全屏模式,返回值以来窗口是否iconified

GLFWAPI void glfwSetGamma(GLFWmonitor* monitor, float gamma)

根据指定的exponent生成一个合适尺寸的gamma ramp(gamma斜度)并设置,参数必须是一个大于0的finite number,用于色彩矫正,理想值是1.

GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* monitor)

获取当前的gamma ramp值

GLFWAPI void glfwSetGammaRamp(GLFWmonitor* monitor, const GLFWgammaramp* ramp)

设置monitor的gamma ramp,第一次调用这个函数并存储gamma的值是在glfwTerminate函数中

GLFWAPI void glfwDefaultWindowHints(void)

reset窗口的所有hints值,全设置为默认的。

GLFWAPI void glfwDestroyWindow(GLFWwindow* window)

destory指定的window和context

GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* window, int value)

设置window的close flag。

GLFWAPI void glfwSetWindowTitle(GLFWwindow* window, const char* title)

设置窗口的title

GLFWAPI void glfwSetWindowIcon(GLFWwindow* window, int count, const GLFWimage* images)

为窗口设置Icon,传入一组备选图像,会选择尺寸接近的作为图标,如果没有传图像,用默认的图标。图像是32bit小端non-premultiplied RGBA8,按行排列从左上角开始。图像的尺寸会根据平台和系统设置进行resize,一般包括16x16,32x32和48x48.

GLFWAPI void glfwGetWindowPos(GLFWwindow* window, int* xpos, int* ypos)

获取指定区域的位置,返回的是屏幕坐标,原点在左上角

GLFWAPI void glfwSetWindowPos(GLFWwindow* window, int xpos, int ypos)

设置窗口坐标,如果是全屏没有效果

GLFWAPI void glfwGetWindowSize(GLFWwindow* window, int* width, int* height)

获取窗口的size,以屏幕坐标为单位,不是framebuffer的尺寸。

GLFWAPI void glfwSetWindowSizeLimits(GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight)

设置窗口的尺寸限制,如果是全屏模式,这个参数只有在创建窗口的时候其作用。其他情况下窗口要是可缩放的这个函数才有作用。

GLFWAPI void glfwSetWindowAspectRatio(GLFWwindow* window, int numer, int denom)

设置窗口的aspect ratio,如果是全屏模式,这个参数只有在创建窗口的时候其作用。其他情况下窗口要是可缩放的这个函数才有作用。aspect ratios是长宽比要大于0。

GLFWAPI void glfwSetWindowSize(GLFWwindow* window, int width, int height)

设置窗口的size.对于全屏窗口,此功能可更新其所需视频模式的分辨率并切换到最接近其的视频模式,而不会影响窗口的上下文。 由于上下文不受影响,因此帧缓冲区的位深度保持不变.

GLFWAPI void glfwGetFramebufferSize(GLFWwindow* window, int* width, int* height)

获取窗口的framebuffer的zise,以pixel为单位

GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* window, int* left, int* top, int* right, int* bottom)

以屏幕坐标为单位检索指定窗口框架的每个边缘的大小。 包括标题栏。函数检索每个窗框边缘的大小,而不是沿特定坐标轴的偏移量,所以检索到的值将始终为零或正数。

GLFWAPI void glfwGetWindowContentScale(GLFWwindow* window, float* xscale, float* yscale)

此函数检索指定窗口的内容比例。 内容比例是当前DPI与平台默认DPI之比。 这对于文本和任何UI元素尤其重要。

GLFWAPI float glfwGetWindowOpacity(GLFWwindow* window)

获取窗苦的不透明度(alpha值),包括所有装饰物。该值时0到1之间的值,初始值为1.

GLFWAPI void glfwSetWindowOpacity(GLFWwindow* window, float opacity)

设置窗口的透明度

GLFWAPI void glfwIconifyWindow(GLFWwindow* window)

如果指定的窗口先前已还原,则此功能可图标化(最小化)指定的窗口。 如果窗口已被图标化,则此功能不执行任何 *** 作。 如果指定的窗口是全屏窗口,则将还原原始监视器分辨率,直到还原该窗口为止。

GLFWAPI void glfwRestoreWindow(GLFWwindow* window)

重置窗口,用在窗口进行了最大化或最小化的情况。如果指定的窗口是全屏窗口,则为该窗口选择的分辨率将在所选监视器上恢复。

GLFWAPI void glfwMaximizeWindow(GLFWwindow* window)

最大化窗口,如果窗口已经最大化,或是全屏模式不起作用

GLFWAPI void glfwShowWindow(GLFWwindow* window)

显示窗口,全屏不起作用,默认情况所有创建的窗口都是显示的,也可以通过glfwSetWindowAttrib设置GLFW_FOCUS_ON_SHOW_hint来设置

GLFWAPI void glfwHideWindow(GLFWwindow* window)

隐藏窗口,全屏不起作用

GLFWAPI void glfwFocusWindow(GLFWwindow* window)

此功能将指定的窗口置于最前面并设置输入焦点。 该窗口应该已经可见并且没有图标。 默认情况下,窗口和全屏模式窗口在最初创建时都会被聚焦。GLFWAPI void glfwRequestWindowAttention(GLFWwindow* window)

该功能要求用户注意指定的窗口。 作用不详

GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* window)

返回指定窗口处于全屏状态的监视器的句柄

GLFWAPI void glfwSetWindowMonitor(GLFWwindow* window, GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate)

设置指定窗口处于全屏状态的监视器的句柄,这个函数会更新monitor的宽、高、视频模式的刷新率。

GLFWAPI int glfwGetWindowAttrib(GLFWwindow* window, int attrib)

获取窗口或GL/ES上下文相关的属性值,framebuffer相关的hints不是属性。

GLFWAPI void glfwSetWindowAttrib(GLFWwindow* window, int attrib, int value)

设置窗口的属性值,支持的属性包含:GLFW_DECORATED、GLFW_RESIZABLE、GLFW_FLOATING、GLFW_AUTO_ICONIFY、GLFW_FOCUS_ON_SHOW。

GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* window, void* pointer)

设置window的user pointer

GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* window)

返回window的user pointer

GLFWAPI void glfwWaitEventsTimeout(double timeout)

等待超时。

GLFWAPI void glfwPostEmptyEvent(void)

向事件队列中插入一个空事件

GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode)

获取窗口输入选项的值,mode取值为:GLFW_CURSOR, GLFW_STICKY_KEYS, GLFW_STICKY_MOUSE_BUTTONS, GLFW_LOCK_KEY_MODS, GLFW_RAW_MOUSE_MOTION。

GLFWAPI void glfwSetInputMode(GLFWwindow* window, int mode, int value)

设置窗口的输入模式,mode取值和get函数一样。

GLFWAPI int glfwRawMouseMotionSupported(void)

查询当前系统是否支持raw mouse motion,是否支持在初始化GLFW的时候一次确定,raw motion接近actual motion,它不受应用于桌面光标运动的缩放和加速度的影响。 该处理适合于光标,而原始运动更适合于控制3D相机。 因此,仅在禁用光标时才提供原始鼠标移动。

GLFWAPI const char* glfwGetKeyName(int key, int scancode)

获取按键名。

GLFWAPI int glfwGetKeyScancode(int key)

获取按键码。

GLFWAPI int glfwGetKey(GLFWwindow* window, int key)

获取按键的最后一个状态。

GLFWAPI int glfwGetMouseButton(GLFWwindow* window, int button)

获取鼠标的最后状态值。

GLFWAPI void glfwGetCursorPos(GLFWwindow* window, double* xpos, double* ypos)

获取光标位置,屏幕坐标。

GLFWAPI void glfwSetCursorPos(GLFWwindow* window, double xpos, double ypos)

设置光标位置,窗口必须有输入焦点,如果没有,这个函数无作用。原点在左上角。

GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot)

创建一个自定义的光标,结合set一起使用,光比较的照片存储和图标的方式一样,按照像素,从左上角开始。

GLFWAPI GLFWcursor* glfwCreateStandardCursor(int shape)

以标准形状创建一个光标

GLFWAPI void glfwDestroyCursor(GLFWcursor* cursor)

销毁一个光标

GLFWAPI void glfwSetCursor(GLFWwindow* window, GLFWcursor* cursor)

设置光标开始在窗口上进行使用,光标要显示害死哟啊设置光标的模式为GLFW_CURSOR_NORMAL。在一些平台上,如果已经有了输入焦点,这个光标就不会显示。

GLFWAPI int glfwJoystickPresent(int jid)

查询 *** 纵杆是否存在

GLFWAPI const float* glfwGetJoystickAxes(int jid, int* count)

返回 *** 纵杆所有轴的值,是一个数组,范围时-1到1

GLFWAPI const unsigned char* glfwGetJoystickButtons(int jid, int* count)

返回 *** 纵杆的所有butto的状态,是一个数组,元素是按下或释放GLFW_PRESS or GLFW_RELEASE

GLFWAPI const unsigned char* glfwGetJoystickHats(int jid, int* count)

返回 *** 纵杆所有hats的状态,返回的也是一个数组

GLFWAPI const char* glfwGetJoystickName(int jid)

返回 *** 纵杆的名字,返回的是字符串

GLFWAPI const char* glfwGetJoystickGUID(int jid)

返回 *** 纵杆的SDL兼容GUID,是一个UTF-8的16进制编码

GLFWAPI void glfwSetJoystickUserPointer(int jid, void* pointer)

*** 纵杆设置一个自动以指针值,

GLFWAPI void* glfwGetJoystickUserPointer(int jid)

返回用户自定义的 *** 纵杆指针值

GLFWAPI int glfwJoystickIsGamepad(int jid)

查询 *** 纵杆是否在gamepad上进行过map

GLFWAPI int glfwUpdateGamepadMappings(const char* string)

添加SDL_GameControllerDB gamepad映射。

GLFWAPI const char* glfwGetGamepadName(int jid)

获取 *** 纵杆游戏设备的名称

GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state)

获取游戏pad中 *** 纵杆映射的状态,用在Xbox等游戏pad上。

GLFWAPI void glfwSetClipboardString(GLFWwindow* window, const char* string)

设置字符串的剪切板

GLFWAPI const char* glfwGetClipboardString(GLFWwindow* window)

获取剪切板的内容,返回的时字符串。

GLFWAPI GLFWwindow* glfwGetCurrentContext(void)

返回当前县城的GL/ES上下文

GLFWAPI int glfwExtensionSupported(const char* extension)

查询指定的GL/ES扩展是否支持

GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname)

赶回当前上下文支持的GL/ES函数地址,包含核心库和扩展库。

callback函数:

GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun callback)

设置 *** 纵杆配置的回调函数,也可以覆盖原来的回调函数,当 *** 纵杆连接或者断开连接的时候调用回调函数。回调函数的格式为:void function_name(int jid, int event)

GLFWAPI GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun callback)

设置monitor的毁掉函数,如果之前又设置,会替换之前的值。

GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* window, GLFWwindowposfun callback)

设置window的position callback,当窗口移动的时候会调用这个回调函数,返回的位置是屏幕坐标的,左上角是原点

GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwindowsizefun callback)

设置窗口size的callback函数,当窗口resize的时候会调用,也是屏幕坐标。

GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwindowclosefun callback)

设置窗口关闭的callback,窗口关闭阿的时候调用。

GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* window, GLFWwindowrefreshfun callback)

设置窗口刷新的callback函数,刷新窗口的时候调用,if the window has been exposed after having been covered by another window.

GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwindowfocusfun callback)

设置窗口的focus回调函数,当窗口window gains or loses input focus时调用.

GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun callback)

设置iconification回调函数,窗口is iconified or restored时调用

GLFWAPI GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(GLFWwindow* window, GLFWwindowmaximizefun callback)

设置窗口最大化的回调函数,窗口最大化或复位时调用

GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* window, GLFWframebuffersizefun callback)

设置framebuffer resize的回调函数,当framebuffer resize时调用

GLFWAPI GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(GLFWwindow* window, GLFWwindowcontentscalefun callback)

设置窗口的content scale回调函数,当窗口的content scale变化时调用

GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwiunning a test, x11perf determinendow* window, GLFWkeyfun callback)

设置按键的回调函数,在按键按下、重复和释放时调用回调函数。

GLFWAPI GLFWcharfun glfwSetCharCallback(GLFWwindow* window, GLFWcharfun callback)

设置字符的回调函数,在输入指定字符编码时调用该回调函数。

GLFWAPI GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow* window, GLFWcharmodsfun callback)

设置字符串编码修改的回调函数。

GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun callback)

设置鼠标按键的回调函数,鼠标按下或释放时触发,回调函数的格式:void function_name(GLFWwindow* window, int button, int action, int mods)

GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun callback)

设置光标位置回调函数,光标移动时触发。

GLFWAPI GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow* window, GLFWcursorenterfun callback)

设置光标进入离开的回调函数,当光标进入或离开屏幕指定区域时触发。回调函数的格式为:void function_name(GLFWwindow* window, int entered)

GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun callback)

设置滚轮回调函数

回调函数void function_name(GLFWwindow* window, int path_count, const char* paths[])

GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun callback)

设置path drop回调函数,当一个或多份额dragged paths are dropped时触发。

vulkan函数:

GLFWAPI int glfwVulkanSupported(void)

查询是否找到Vulkan loader and any minimally functional ICD

GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count)

返回GLFW需要的Vulkan instance extensions,返回的个数组,里面包含了,创建vulkan surface时GLFW要的Vulkan实例扩展。

GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, const char* procname)

返回specified Vulkan instance函数地址.

GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily)

查询当前GLFW编译的指定物理设备的queue family是否显示图像

GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface)

创建一个surface。

#include <unistd.h>

#include <尘昌ioctl.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>派春扒

你是想用framebuffer吗,(好象是这么拼写的森槐,忘记了)。。。。

步骤/方法

一、下载源代码漏中没和编译软件的准备

下载内核源代码:http://www.kernel.org/

注意,点击2.6.25内核的F版,即完整版。

如果你懒得去网站点联接,运行下列命令:

代码:$cd ~$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.25.10.tar.bz2

安装有关编译程序。安装make ,gcc, make-kpkg,运行menuconfig等等和编译内核相关的工具。安装不了,请检查/etc/apt/sources.list 文件。有关命令:代码:$sudo apt-get install build-essential kernel-package libncurses5-dev

二、解压源代码注意,网上很多教程上说应该解压到 /usr/src,纯属以讹传讹,linux掌门人linus说解压到任何目录上都可以。当然,linus的培姿说法是正确的。我放在自己的主目录下的src目录。如果你下载源代码是放到自己的主目录下或者运行上面的wget下载的,那么运行下列命令:代码:$ cd ~$ mkdir src &&tar jfx linux-2.6.25.10.tar.bz2 -C src/现在,源代码就在 ~/src/linux-2.6.25.10进入源代码的目录,准备下一步的工作。后面都在这个目录里面进行。代码:$ cd ~/src/linux-2.6.25.10

三、开始编译前的准备工作。首先,清理以前编译时留下的临时文件。如果是刚刚解开的包,不需要执行这步。如果是第二次或者是第n次编译,那么一定要执行。相关命令如下:代码:$ sudo make mrproper网上很多教程上说把现在使用的内核的config拷贝过来参考,据实验,是不需要的,ubuntu还有debian会自动做这步。不过这条命令倒是可以学习一下。当然你可以将以前的配置拷贝过来。命令:代码:cp /boot/config-`uname -r` ./.config

四、开始配置内核选项。相关命令:代码:$sudo make menuconfig配置用到的键只有几个,esc退出菜单空格改变选项状态光标键上下左右移动,回车选定。选项意义:M是编译成可以随时加入的模块,*是编译进入内核,空就是不要。配置选项非常多,具体配置可以参考金步国先生翻译的资料:Linux 2.6.19.x 内核编译配置选项。参考网址:http://lamp.linux.gov.cn/Linux/kernel_options.html为了一次成功,请大家遵循一个原则,如果你自己使用的内核已经选用了某个选项,如果你没用充分的理由,不要随便改动。这样虽然内核不那么精简,但是不容易出现问题。我们可以精简的部分是硬件模块部分,对于自己没有的硬件要毫不犹豫的清除。如果你很执着,或者你有洁癖,你也可返纳以一项项对过去,按照金步国先生的资料描述去选择基本上没有问题。

五、必须强调的几个选项:1、

在“General setup”里面的“Prompt for development and/or incomplete

code/drivers”金步国认为是不需要。但是如果你的硬件比较新,那几乎是必须选的,这样,我们才可以找到4965无线网卡,alsa声音驱动等

等。Kernel log buffer size 我选15,双核。如果你用ia64,要选16。Control Group support 集群支持?可以不要Choose SLAB allocator (SLUB (Unqueued Allocator)) 内存管理模式slab和slub选择slub。

2、在“Block layer”里,假如没有2TB的硬盘,就去掉:Support for Large Block Devices 。Support for Large Single Files 也不需要,谁有2TB的文件?

3、Processor type and features中是关于cpu的,要认真选。Symmetric multi-processing support是打开多核的开关,我的cpu是双核的,选中。Processor family (Core 2/newer Xeon) 我的是Core 2/newer Xeon。找到自己的cpu后,把Generic x86 support选项取消。Subarchitecture Type 选(PC-compatible)Maximum number of CPUs 输入自己的核心数目,我输入2。SMT (Hyperthreading) scheduler support说的是超线程技术,P4有支持的,我的t8100不支持,目前大部分市场上的家用cpu都不支持。High Memory Support (4GB) 1G以下选1G;我是3G,选4G;4G以上的选16G在“ Timer frequency ”里,默认是250Hz,较新的cpu都可以选择了1000Hz,性能更好。

4、Power management options中把APM (Advanced Power Management) BIOS support关闭。现在的电脑都用acpi了。CPU Frequency scaling 是笔记本cpu节电技术Default CPUFreq governor (conservative) cpu节电模式有四个,笔记本默认选conservative比较好。ACPI Processor P-States driver 必须选,不然CPU Frequency就不能用。后面的可选自己硬件相关的,我选的是Intel Enhanced SpeedStep和 Intel Speedstep on ICH-M chipsets,其他的统统消灭。

5、Bus options的选择:Bus options (PCI, PCMCIA, EISA, MCA, ISA)PCI support PCI Express support 现在新买的机器基本上都是PCI Express了ISA support 较新的新机器没有ISA设备,可以去掉MCA support 去掉NatSemi SCx200 support 去掉PCI Hotplug Support Support for PCI Hotplug (EXPERIMENTAL) 如果没有PCI热插拔设备,去掉这里的选项可以考虑全部编译进内核,而不是以模块形式存在。

6、Device Drivers是重点,由于linux不但面向个人工作站,更多的是面向服务器的应用,所以可以把自己机器上没有的硬件全部去掉,而不用面面俱到。但是通用型的选项要慎重。比如在网卡的部分,除了我的千兆网卡 Broadcom Tigon3 support和4965无线网卡Intel Wireless WiFi 4965AGN,其余的硬件支持统统去掉。再比如声卡部分,我的是hd声卡,我只是在PCI devices中,选intel hd 声卡,再选Build IDT/Sigmatel HD-audio codec support,除此之外的硬件支持全部去掉。

声卡还有一个细节,在ubuntu7.10里面, 需要在/etc/modprobe.d/alsa-base后面添加options

snd-hda-intel probe_mask=1

model=3stack,这样我的笔记本喇叭才可以发声,不然只有外接耳机或者音箱。这次编译以后,这个动作就不必了,但是两个耳机插口只有一个可以用

了。再比如我的电脑中没有agp,就可以直接把agp相关的选项全部取消。要注意的:ATA/ATAPI/MFM/RLL support Include IDE/ATA-2 DISK support 如果你的/boot是放在IDE硬盘上,那么这里一定要选*,选M都不行。否则启动时会出现“waiting for root file system”的提示而停滞不前。 SCSI emulation support 要用刻录机,必须选。SCSI device support 现在都是SATA硬盘,一定要选* SCSI disk support 如果你的/boot放在SATA硬盘上,一定要选*。

SCSI CDROM support 虽然康宝刻录机是ide接口的,但是必须把它当成scsi接口的,这是老问题了。用刻录机,必须选。

Graphics supportSupport for frame buffer devices 选中,进入选择 VESA VGA graphics support 选上,不然字符界面启动会有问题,后面的显卡选择:由于我的显卡是nvidia 8400gs,要自己安装nvidia公司的驱动,所以一个都没有选。这样导致ubuntu开机动画会出问题,我索性在grub中的splash字符全部删除,把开机动画关闭。字符界面很正常。 Console display driver support 有人开机后字符控制台错误,就是这部分选项没有选,出问题了。 Framebuffer Console support 需要打开。

Bootup logo 开机图标,会在自检的画面上加上个性图标。需要在grub上添加“vga=”的选项,可以参考http://dotimes.com/articles /t23-slackware-framebuffer.html7、File systemsFilesystem in Userspace support 简称fuse。是必选的,如果你要用windows分区。

CD-ROM/DVD Filesystems ISO 9660 CDROM file system support 一般选*DOS/FAT/NT Filesystems VFAT (Windows-95) fs support 有FAT32分区就选*吧 NTFS file system support 有NTFS分区就选*吧 NTFS write support 如果想对 NTFS分区进行写 *** 作,选*必须将启动盘的文件系统编译进内核,默认是编译成模块,这样无法启动系统。ubuntu采用的文件系统是ext3,请把ext2,ext3相关的必要选项都编译进入内核。

8、Virtualization这个大类是我多花几百元买t8100的主要原因,因为t8100支持intel vt技术使linux上的虚拟机的性能大幅度提高。这里的选项我除了amd的,其他都编译成模块。

9、全部设置完成,最后一项是保存设置。按照我的习惯,先在上一层目录保存一个备份,文件名类似 ../config20080630然后再保存到当起目录,文件名 .config退出设置程序。

六、开始编译内核。ubuntu的工具是make-kpkg,和其他的发行版相比,步骤相对简单。相关命令:代码:$sudo make-kpkg clean 这条命令好像不要超级权限,很多资料上说要,不过这不是原则问题。

$ sudo make-kpkg -initrd --initrd --append-to-version=dell1400 kernel_image kernel-headers上述命令中的dell1400可以用自己喜欢的字符代替,最后的字符一定是数字.输完上述命令回车之前,建议大家把浏览器还有别的运用程序都关掉,机器开始的工作比较艰苦。

我的机器大概十几分钟。

七、安装内核编译完成就是安装工作。编译好的内核在上一层目录。包括linux-headers-...-_i386.deb和linux-image-...-i386.deb两个文件,如果你不搞开发的话,只要安装内核就可以,头文件以后要用的时候再说。安装相关命令:

代码:$ cd ..$ sudo dpkg -i linux-image-(按tab键)文件名很长,如果不用tab自动补足是不可能的,tab键万岁。安装完成后和老内核比较一下大小代码:

$ ls -l /boot/

八、重新启动验证新内核。代码:$ sudo reboot

九、显卡驱动如果你的显卡和我一样是nvidia显卡,启动之后往往无法正常进入x-window。即使能看到gdm登录界面,效果也是很差的。那么就要安装nvidia驱动。用ctrl+alt+f1 进入字符命令行,输入用户名,密码登录。命令:代码:下载驱动$ wget http://us.download.nvidia.com/XFree86/Linux-x86/173.14.12/NVIDIA-Linux-x86-173.14.12-pkg1.run$sudo -s输入密码取得超级权限。#ps ax看看和gdm相关的进程,把这些进程全部关闭用sudo /etc/init.d/gdm stop有可能有一个进程没有关闭:#kill 进程号然后安装nvidia显卡驱动,当然驱动要先下好,到nvidia驱动所在的目录里,运行:# sh ./NVIDIA-Linux-x86-173.14.12-pkg1.run重新启动以后就ok。要用nvidia的驱动,每次升级内核都要这么做。

十、无线网卡相关的内核选项是Networking --->Wireless --->Generic IEEE 802.11 Networking Stack (mac80211)还有4965的驱动。4965

无线网卡驱动虽然已经编入内核,但没有firmware无法使用。需要把原来内核的firmware拷贝到新内核对应的目录,名字和内核一致,我的内核是

linux-image-2.6.25.10dell1400,那建的目录名就是2.6.25.10dell1400。代码:具体命令:$ cd /lib/firmware/$ sudo mkdir 2.6.25.10dell1400把你的老内核中的4965的firmware拷贝过来。$ sudo cp 2.6.24-16-generic/* 2.6.25.10dell1400/上面的命令和下面的命令是等价的:$ cd /lib/firmware/$ sudo cp -R 2.6.24-16-generic/ 2.6.25.10dell1400/

重新启动系统,无线网卡就正常了。

附编译使用的机器配置:dell vostro 1400,t8100,nvidia 8400cs显卡,内置SigmaTel STAC9228芯片的声卡,4965无线网卡,BCM5906M千兆网卡,3G内存,160G硬盘,combo刻录。

编译系统版本:ubuntu 8.04桌面版.


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12127503.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存